On 09/26/2011 01:58 PM, Matias wrote:
1) Is there a reason why native form validation seems to be tied to the click 
of the submit button? Submitting the form using JavaScript does not seem to 
trigger HTML5 form validation in either Firefox, Opera or the Webkit browsers 
(I haven't checked how IE10 behaves yet). To me this seems like an unnecessary 
limitation.

.submit() by-passes all possible submit cancellation per spec: there is no submit event sent and given that the validation checks were done in the submit event handler, it seems reasonable to disable the automatic HTML5 form validation.

2) How about adding a method to programmatically display the native validation 
error messages instead of waiting for the form submit click? We already have a 
way to (more or less) detect if the form is valid or not, but no way of forcing 
the native validation error messages to render without using some submit button 
click hack.

I guess submitControl.click() should work and isn't that hacky.

3) Should there be a way of detecting if the browser actually understood all 
input element types? Browsers believe that a form is valid even when it 
contains invalid data for input types the browser doesn't understand. (Like the 
string 'asdf' in an input type=number field in Firefox.)
>
So checking if the browser has a checkValidity method is not a guarantee that 
the form validates according to the HTML5 specified constraints. If there was a 
method or property like form.containsUnknownInputs and maybe 
element.isUnknownInput (not the best names, but you get the idea) we could 
determine the best way to handle further validation.
So, theoretically, you should be able to do:
  input.type = "foo";
  if (input.type == "foo") {
  }

But last I checked Webkit brokes that by recognizing types it does not [fully] understood. Though, maybe the validation is done as expected.

However, I don't think it would be a good idea to have a website using only HTML5 Form Validation for a wide audience. It is better to have a path for browsers who do not understand HTML5 Forms Validation. Basically, that means keeping the checks in the submit event handler. These checks will be done for non-supported types too.

--
Mounir

Reply via email to