HTML5 attribute priority - forms

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.

Related

Angular Material: Usage of errorStateMatcher with ngFor

I'm using Angular 6.0.9 and Angular Material 6.5.4. In my form I have an ngFor loop for the inputs with an errorStateMatcher to validate the input.
The problem is that if the content of an input field is invalid, all other fields will also be marked as invalid (even if they are not dirty). I want to make sure that only the current field that is actually invalid is marked as red.
See a self-explanatory example on stackblitz:
https://stackblitz.com/edit/angular-s1jyhw?file=app%2Finput-error-state-matcher-example.html
Your inputs all share the same form control emailFormControl. You need a separate form control for each input. It is okay to use the same ErrorStateMatcher but not FormControl

Symfony2 Field Type Guessing: When is <textarea> chosen (over <input type="text">)?

Not declaring the field type brings the advantage that Symfony infers the required and maxlength attribute from validation rules, as explained here: http://symfony.com/doc/current/book/forms.html#field-type-options-guessing
However, I can't find a way to make Symfony 2.8.2 "guess" a <textarea> instead of an <input type="text"> :-(
My first idea was to increase the allowed length, but even with Length: max: 100000 in validation.yml, Symfony is unimpressed and just gives me <input type="text" maxlength="100000" />.
EDIT: #chalasr: I'm talking about an entity which is not mapped to the database. Sorry for not mentioning that earlier!
The FormBuilder guesses the field type by checking the type in the mapping of the corresponding property, in the entity.
Use text instead of string as type of your column mapping, and the FormBuilder will use a textarea instead of an input.
Example :
/**
* #ORM\Column(type="text")
*/
protected $field;
Output with $builder->add('field'); :
<textarea id="entity_field" name="entity[field]" required="required"></textarea>
For more info look at the Symfony\Bridge\Doctrine\Form\DoctrineOrmTypeGuesser.
Update
So, you don't use a mapped class.
Look at the FormBuilder, as you can see, if there is no corresponding Guesser found, the form type will be a TextType (input text).
Otherwise, there is 3 different Guesser:
FormTypeGuesserChain
DoctrineORMTypeGuesser
ValidatorTypeGuesser
Because your class is not mapped, Symfony will use the ValidatorTypeGuesser to guess the type of your field.
This Guesser looks for constraints in your class.
For example, if your field has a Type constraint with type integer, the NumberType will be used and an input type number will be rendered.
My first idea was to use a Length constraint with a big min-length.
But, after many tries and looks in classes, it seems the TextareaType is never guessed, unless your class is mapped and your field has text as type (DoctrineTypeGuesser is used) .
So, without a mapped class, Symfony cannot create a textarea from type guessing.
For more informations look at the ValidatorTypeGuesser::guessTypeForConstraint.
See also the Form Type Guessing chapter of documentation, it shows how create your own TypeGuesser with a good example.

Form validation in Polymer

I have Polymer application and I want to check if given inputs are NOT EMPTY on form submission. I have some inputs set to required but I don't have any way to check if those fields are NOT EMPTY. I can only check if given pattern is matched by checking invalid attribute but even for required fields pattern is .*.
Is there any wait to do it? Or is it in beta and this feature has not been implemented yet?
Polymer.dart <= 0.16.x
You can set a pattern yourself
<paper-input floatinglabel
label="Some label"
value='{{someValue}}'
pattern="^.+$"
error="Input required">
</paper-input>
Or see
Taking total control of PaperInput validation
for complete control of validation.

What's the difference between novalidate and formnovalidate attributes of HTML5?

From w3c schools we have these definitions:
novalidate:
When present, it specifies that the form-data (input) should not be
validated when submitted.
formnovalidate:
When present, it specifies that the element should not be
validated when submitted.
Does it make any difference using formnovalidate in the submit button insted of using novalidate in the form?
(I really don't get the difference)
novalidate is applied to the form, and prevents it from being validated; formnovalidate is applied to a submit button, and overrides the novalidate option, if present; it means 'submit this form without validating, regardless of the general form setting'.
The example given in the spec is when a user is saving data rather than publishing it; the data might be incomplete and invalid, but doesn't require validation to be saved.

Is it possible to pass post data to the form (prefill form with data)?

For example https://stackoverflow.com/questions/ask there we have form id="post-form" which has method="post", is it possible somehow open this form and have lets say Name input (display-name) with my name prefilled on load?
Yes. You can do this many ways, with Javascript by setting the input's text, or you can do it server-side with PHP by echoing "value=\"$name\"" for the value attribute of the input.