Symfony2 - apply attribute to radio buttons - forms

I want to add an attribute to a radio-button form input. I want to add jquery validation to them. When I specify the attr in the form_widget function in twig, the attributes are applied to the div where the input elements are in.
How do I apply the attributes to the input element?

Related

Angular reactive form custom validation

I am trying to make reactive form custom validation, From multiple set of inputs [text-boxes, radio button, select], Form get validated with true when any two input fields are filled or entered.
For custom validation in form , you can set flag by check form control value in if condition and display message in HTML with that flag.
Example:
In the TS file:
flag:boolean;
if(this.demoForm.value.phone && this.demoForm.value.pin){
this.flag=false;
}else{
this.flag=true
}
In HTML file:
<span *ngIf='flag'>Your form is invalid</span>

Grouping Form Zend not posting Data of Second Form?

I have 2 Forms, which I am usingain another form to try and keep things DRY.
In this manner:
#Forms/my_form.php
$this->addSubForm(new Form_thisForm(), 'this form');
$this->addSubForm(new Form_thatForm(), 'that form');
//then i add 2 more elements a sort and order element
//then a submit
So in the view where the form is used, all the fields show from all forms included.
However when posting the form data only the fields from Form_thisForm() and the Form_myForm(), ie. the main form, are posting. Data or form element names are not posting from Form_thatForm().
The post only contains variables in the 1st subform and full form. Not the second subform.
I guess your Form_thisForm and Form_thatForm are inherited from Zend_Form, so they also have Form decorator (which basically wraps your subforms in <form> tag).
As a result you have nested <form> tags in your html and this is not valid.
You should inherit your subforms classes from Zend_Form_SubForm - it has no Form decorator by default.

Symfony Form Type with multiple input fields

With Symfony 2.1, how can I create a form type with multiple input fields in it?
So in the form builder I want to add a custom form type :
$builder->add('test','my_fieldtype')
Then if I do this in the template :
{{ form_row(form.test) }}
I want it to display a row that has a label and 2 or 3 input fields. Something like the date type I suppose.
You will need to create a custom field type. The best way to achieve it is to look at the code of the DateTimeType.
Remember to create as well the appropriate Twig form template.

HTML5 attribute priority

Html5 has new attributes like the novalidation attribute for the form element and the required element for an input element.
When using both of this type of attributes, what sort of attribute have a higher priority, the form attributes or the input attributes?
The novalidate attribute specifies that the form should not be validated when submitted. If this attribute is present the form will not validate form input. (source: http://www.w3schools.com/html5/att_form_novalidate.asp)
This means it won't validate required input items, the format of email and url input types and so on. It essentially means "allow any input".
novalidate turns off HTML5 form validation for a form, that is, a required input field in that form won't be validated on submission.
Judging by the information from w3schools here and the working example here I would say that the novalidate attribute always overrules form-elements, even when they have the required attribute.

Every form element with its id starting with a tag

I got 2 forms in 2 different div's which are hidden, if the user clicks on one (login, register) the relevant div is shown.
I've named the form fields like reg_username, reg_email ... and the login fields are named login_username login_password.
Now i've created a function which validate the fields. When i step through with this part of code
$("#account").find(':input').each(function(i) {
});
it finds every form field.
the div #account is my main div where all fields are in from the 2 div #register and #login. There are serval other input fields in those 2 div's.
Depending on the div i only want to check fields starting with a tag (reg or login), is there a way to get only this div's and not all?
For register:
$(":input[name^='reg_']").each(function(){
// validation stuff here
});
and for login:
$(":input[name^='login_']").each(function(){
// validation stuff here
});
These selectors match only those form inputs whose name attribute starts with reg_ and login_, respectively.
If your 'tags' (reg_ and login_) are in the id of the elements and not the name, just change name to id in the code above.
See the attributeStartsWith jQuery selector.