28.07.2011 03:21, Ian Hickson wrote:

A text input field could have a number of error conditions:

Indeed. Therefore it would be essential to be able to set the error message for _each_ check that a browser is supposed to do on the basis of HTML markup alone. If this is not possible, it is easier to authors to code all data checking in JavaScript. Setting the error messages is important both for context dependency and for localization (using the language of the browser's UI would be odd when it differs from the language of the page - if the page is in Greek and the instructions there are in Greek, I would expect the messages of the data error to be Greek, even when my browser speaks Hebrew).

I guess we can have a dedicated attribute that user agents can use
to provide a message, rather than the current solution of just using the
title="" attribute for pattern=""'s error message.

The title="" attribute is generally supposed to contain an advisory title for an element, and deviating from this that way is very odd and confusing - especially since user agents may show its value in a tooltip or speak it out when entering the field.

A dedicated attribute is much better. In particular, it does not interfere with the existing use of existing attributes.

If it's present, user
agents could use it to replace or augment their message, and authors could
make the message more specific by dynamically changing the attribute when
during the 'invalid' event handler.

    <label>  Offer code:
     <input type=text maxlength=8 pattern="[a-z1-9]+" required
            oninput="setCustomValidity(input.match(/0/) ?
                     'Codes contain no zeroes, only Os.' : '')"
            validitymessage="Enter the code without spaces.">
    </label>

It would be more logical and descriptive to call it errormessage rather than validitymessage.

But the main problem is that attributes like maxlength, pattern, and required are supposed to provide some data validation in a simple manner that does not need to involve JavaScript and works even when it is disabled. To make them useful, it should be possible to set the error message for each of them separately in HTML.

I have no better solution than to use separate attributes, like maxlengtherror, patternerror, requirederror. This doesn't sound cool, but it would work and would be useful.

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Reply via email to