triggering contextual error message for inputs

4 views
Skip to first unread message

Da Scritch

unread,
Feb 9, 2012, 10:14:24 AM2/9/12
to
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)

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 in MDC, nor into inspecting <input>
and <form> elements.

Sorry my french.
Xavier Mouton-Dubosc
http://Dascritch.com
@dascritch

Mounir Lamouri

unread,
Mar 18, 2012, 1:31:50 PM3/18/12
to dev-te...@lists.mozilla.org
First of all, sorry for the quite late reply...

On 02/09/2012 04:14 PM, Da Scritch wrote:
> How can I trigger the browser (firefox, chrome, etc...) to display
> their standard contextual error-message ?

Unfortunately, you can't really do that. form.submit() will by-pass the
form validation check. The only way to trigger the form validation check
is when the user tries to submit the form. IIRC, there was a discussion
on whatwg about adding a way to trigger the browser's form validation
check (and the UI) but I can't find it...

Cheers,
--
Mounir
Reply all
Reply to author
Forward
0 new messages