How can I add plain HTML form input to Joomla frontend article submission override and save to DB _content ~ attribs table? - joomla3.0

I created a frontend override of com_content/views/form/tmpl/edit.php and added a plain ol' HTML input field within the <form> as below:
<input type="text" name="jform[attribs][vidurl]" value="" id="jform_attribs_vidurl" />
I expected the data to be saved in the _content/attribs table but it just returns null as if the name is not passed during POST.
It worked properly for the image field
I did the same for the image_intro field and that value saves correctly.
I deleted line
<?php echo $this->form->renderField('image_intro', 'images'); ?>
and used
<input type="hidden" name="jform[images][image_intro]" id="jform_images_image_intro" value="" />
Then pass the image path value from a AJAX process after successful upload via file input field, to the hidden image field via javascript. The data saves successfully on submit.
Is it that there must be an existing XML string with the field attributes?
Does JFORM ignore HTML fields if its attributes are not found in a xml string? How can I get a custom added field to save?
The custom form output

Related

how to validate on form submit using AngularJS

I am very much new in angular js.I want to validate and post the form data using angular js on submit.I searched google but most of them was
disable the button on load ,after completing the form with valid data the button enable but I want to show error messages on form submit.
Here is My form snapshoot
I have tested with two text fields one is name and other is email but I want to proper messages for each fields e.g for email,phone no (valid format) and empty fields now I get only empty field message.
<span class="error-message"
ng-show="showMessage(frmReg.name)">
Please complete this field.</span>
var app=angular.module('regForm',[]);
app.controller('FormController',function($scope,$http){
$scope.frmRegField={};
$scope.frmSubmit=function(){
angular.forEach($scope.frmReg.$error.required, function(field) {
field.$setDirty();
});
// $http({
// method:"POST",
// url:"form_submit.php",
// data:$scope.frmRegField
// }).success(function(data){
// });
};
$scope.showMessage=function(input){
console.log(input.$$attr.name);
var show = input.$invalid && (input.$dirty || input.$touched);
return show;
};
});
You could use either class or state to do what you need
Input fields have the following states:
$untouched The field has not been touched yet
$touched The field has been touched
$pristine The field has not been modified yet
$dirty The field has been modified
$invalid The field content is not valid
$valid The field content is valid
They are all properties of the input field, and are either true or false.
Forms have the following states:
$pristine No fields have been modified yet
$dirty One or more have been modified
$invalid The form content is not valid
$valid The form content is valid
$submitted The form is submitted
The following classes are added to, or removed from, input fields:
ng-untouched The field has not been touched yet
ng-touched The field has been touched
ng-pristine The field has not been modified yet
ng-dirty The field has been modified
ng-valid The field content is valid
ng-invalid The field content is not valid
ng-valid-key One key for each validation. Example: ng-valid-required, useful when there are more than one thing that must be validated
ng-invalid-key Example: ng-invalid-required
The following classes are added to, or removed from, forms:
ng-pristine No fields has not been modified yet
ng-dirty One or more fields has been modified
ng-valid The form content is valid
ng-invalid The form content is not valid
ng-valid-key One key for each validation. Example: ng-valid-required, useful when there are more than one thing that must be validated
ng-invalid-key Example: ng-invalid-required
The classes are removed if the value they represent is false.
Give the form a name:
<form name="myForm">
And a name for the input to:
<input type="text" name="myName">
Then use ng-show/ng-if in your span:
<span class="error-message" ng-show="myForm.myName.$touched && myForm.myName.$invalid">
Please complete this field.
</span>
You can use ng-disabled to validate submit too:
<input type="submit" value="Submit" ng-disabled="myForm.$invalid">
Hope this helps. Good luck!

cy.get() input using ng-model attibute?

Lets say I've got the following form with two input elements.
Title:
<input type="text" ng-model="detail.message.title">
Description:
<input type="text" ng-model="detail.message.description">
To get Cypress.io to fill in the text input I should use code like
cy.get('<selector>').type('Here the data for the title')
The text input has no class, name or ID so I was wondering if it would be possible to select text input using the 'ng-model' attribute?
Try attribute selector input[ng-model="model name here"]and see if it is working.
ex:
cy.get('input[ng-model="detail.message.title"]').type('Here the data for the title')
Note: It is entirely based on your requirement but I feel this is not recommended, Instead you can add a class or ID and use respective selector, because if the attribute value changes in future then you have to change in Cypress as well.

How to get form data in dynamic form in Angularjs?

I have created dynamic form, here I want to send form data to controller. How can do this?
Here is plunker code link https://plnkr.co/edit/xmxDJHTPfJoSFwa2FWCB?p=preview
Issues:
when I change the value then element label also change.
How can I get the form data in product_submit function of controller.
All response appreciated.
Use
<input type="text"
id="module_module"
ng-model="getCol.value"
required="required"
class="form-control col-md-7 col-xs-12"
placeholder="Enter {{getCol.Field}}"
/>
Look here ng-model="getCol.value". You are using filed name as text field model value. Filed name and value are different. That is what you want I suppose.
You can access the values easily from your controller as $scope.getColumn[1].value. Change index or iterate accordingly.
Plunker here
To solve label issues, in your html, I changed ng-model expression to bound into getColumn.Value
In controller, I can read value entered in scope.getColumn[i].Value
I also updated code https://plnkr.co/edit/KlhAb69seMzHsLuhqweR?p=preview

AngularJS clears input fields populated with Laravel form model binding

I am new to AngularJS and i work Laravel. When i fill my input fields with Laravel form model binding, and i set ng-model="title" on input field, AngularJs clears populated input and sets it's value to '';
When i comment ng-model="title", field is populated.
on page load for few miliseconds input field is populated, and i think when AngularJS initializes $scope, input fields become empty.
I have not any controller in angular and when i add angular to page this problem appears.
How can i prevent angular from clear input fields, that are filled for edit action?
I found an good answer. we should set value, on input element via ng-init directive. so value will be accessible on scope and input filed will be populated:
<input ng-model="title" ng-init="title='{{ $title = $post->title }}'" value="{{ $title }}" type="text">
Now i use this solution.

How to pass an array as a hidden field?

I am implementing an auto complete box using the Ajax.autocompleter method of the scriptaculous.js framework.
This is the auto complete box and the div where the auto suggested entries are populated.
<?php echo $form->create('Share', array('url' => '/forms/share')); ?>
<label for="shareWith">Share Form with</label>
<input type="text" id="autocomplete" name="autocomplete_parameter"/>
<div id="autocomplete_choices" class="autocomplete"></div>
<input type="hidden" id="sharedUserId" name="sharedUserId"/>
<?php echo $form->end('Share');?>
This is the JQuery function to get the auto-suggested list and to get the id of the selected entry which is stored in the hidden field of the form.
new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
"http://localhost/FormBuilder/forms/autoComplete",
{
tokens: ',',
afterUpdateElement : getSelectedId
}
);
function getSelectedId(text, li) {
$("#sharedUserId").val(li.id);
}
Suppose if I select multiple entries,how to send those values?
Can I have an array as a hidden field, so that I can have an array of the selected elements and save that array as a hidden field?
Simply create a new hidden input field for every selected ID, and make sure that for each you have name="sharedUserId[]". This doesn't follow the CakePHP form element naming convention, but it will make sure that the POSTed value of sharedUserId is an array.
serialize with json and parse it in the server back. PHP 5.2 can parse json natively.
Not related to your question though..
http://docs.jquery.com/Plugins/Autocomplete
jQuery Auto complete you

Resources