This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17826 - Triggering contextual error message for inputs
Summary: Triggering contextual error message for inputs
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 enhancement
Target Milestone: 2013 Q4
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-18 06:56 UTC by contributor
Modified: 2013-10-03 21:59 UTC (History)
15 users (show)

See Also:


Attachments

Description contributor 2012-07-18 06:56:01 UTC
This was was cloned from bug 16051 as part of operation convergence.
Originally filed: 2012-02-21 08:18:00 +0000
Original reporter: Xavier Mouton-Dubosc <xaviermd@gmail.com>

================================================================================
 #0   Xavier Mouton-Dubosc                            2012-02-21 08:18:08 +0000 
--------------------------------------------------------------------------------
Hi everyone

I'm actually dev'ing on a intranet application in HTML5 with XHR (so
sorry, but i can't give access to any example). You can see a test there : http://jsfiddle.net/bz88V/

For a <form> I wish on make an XHR, I test the validity of the form,
like this :

if (form.checkValidity())
{
  $.post([...]);
} else {

   errormessages();

}

on the same way, into the return of the post (the [...] part), i can
have error validating messages from the server. So I attach them to
the inpts like this :
input.setCustomValidity(le_error_message);
le_error_message is really attached as I can see into
input.validationMessage
the :invalid css selector is set to the input but...

How can I trigger the browser (firefox, chrome, etc...) to display
their standard contextual error-message ?

I tried form.submit(), but it will really submit the form, even
skipping what I wish the browser should do.
I can't see any reference to that, nor into inspecting <input>
and <form> elements.


French speaking paper http://dascritch.net/post/2012/02/21/Validations-complexes-de-HTML5-farcies-au-Javascript

Sorry my french.
Xavier Mouton-Dubosc
  http://Dascritch.com
  @dascritch
================================================================================
Comment 1 Ian 'Hixie' Hickson 2012-09-26 18:34:37 UTC
Just catch the form submission using a regular submit button, as in:

   <form action="javascript:void(0)" onsubmit="submitted()">

...or some such, instead of doing the submission yourself with checkValidity(), etc.

Does that work?
Comment 2 Xavier Mouton-Dubosc 2012-10-22 12:09:26 UTC
Sorry to not have answered in time.

I did it by not using the async mode of $.post in jquery, then fallback to the normal event to have the form failing.

The code became
if (form.checkValidity())
{
   $.ajax({ async : false });
   // populating the returned errors into custom validity
}

return true;

BTW, using javascript: link or on*="" attribute is really ugly ;)
Comment 3 Ian 'Hixie' Hickson 2012-10-22 18:37:25 UTC
Why is it ugly?
Comment 4 Ian 'Hixie' Hickson 2012-11-24 04:21:10 UTC
This bug is not the only request I've seen for a way to explicitly trigger the user agent's form validation UI. Maybe we should add something after all.
Comment 5 Ian 'Hixie' Hickson 2013-10-02 20:08:57 UTC
I'm thinking we should supplement every checkValidity() method with a reportValidity() method. On the <form> element it would be the same as checkValidity() except for invoking "interactively validate the constraints" rather than "statically validate the constraints". On form controls, it would do the same but only looking at that one form control.

Any objections?
Comment 6 Xavier Mouton-Dubosc 2013-10-02 20:20:27 UTC
This seems good.
Comment 7 Kent Tamura 2013-10-03 14:05:59 UTC
(In reply to Ian 'Hixie' Hickson from comment #5)
> I'm thinking we should supplement every checkValidity() method with a
> reportValidity() method. On the <form> element it would be the same as
> checkValidity() except for invoking "interactively validate the constraints"
> rather than "statically validate the constraints". On form controls, it
> would do the same but only looking at that one form control.

It sounds good.
We'd like to implement it in Blink.
Comment 8 Ian 'Hixie' Hickson 2013-10-03 21:59:25 UTC
Ok, done.
Comment 9 contributor 2013-10-03 21:59:32 UTC
Checked in as WHATWG revision r8210.
Check-in comment: Add reportValidity(), which is like checkValidity() but triggers the browser's error-reporting UI as well
http://html5.org/tools/web-apps-tracker?from=8209&to=8210