Re: [css-ui] Request for :dirty pseudoclass

On Wed, Sep 23, 2009 at 8:42 AM, Tab Atkins Jr. <jackalmage@gmail.com> wrote:
> I recently opened a bugzilla ticket on the HTML5 tracker[1] asking for
> :invalid and related pseudoclasses to not match until the input was in
> some sense "dirty", that is, until the user had directly interacted
> with the control.  Hixie closed the ticket with WONTFIX and provided a
> good reason for doing so - there are many reasons why you *would* want
> immediate validation - as well as providing a suggestion for manually
> implementing 'dirty' detection in a way that would interact with CSS
> appropriately.
>

What does the :dirty pseuodoclass apply to? FORM, FIELDSET, or just
form controls?

form:dirty    *:invalid {
  border: 1px solid red;
}

fieldset:dirty   *:invalid {
  font-weight: 800;
}

An associated "dirty" state property would be useful for form change events.

if(FormManager.isFormDirty(form)) {
  // re-enable button.
}

var FormManager = {};

FormManager.isFormDirty = function(form) {
  var formDirty;
  // Native code performance boost!
  if(typeof form.dirty == "boolean") {
    formDirty = function(form) {
      return form.dirty;
    }
  } else {
  // hand-rolled fallback.
    formDirty = function(form){
      var dirty = false;
      // manual check.
      return dirty;
    }
  }
  return (FormManager.isFormDirty = formDirty(form));
}

This is more of a DOM related issue than CSS, but somewhat related to
the "dirty" idea.

> This seems silly to have to do manually, though, as most of the time
> you *will* want to delay error messages until the user has interacted
> with the input.  As well, it depends on js, which means that users
> without js won't see the validation styling at all (without some
> annoying hacks around the issue).
>

Programmers care about data format. Obviously designers might have a
different opinion on what the user gets presented with.

> I propose a :dirty pseudoclass be added to CSS UI.  It would match any
> input that the user has significantly interacted with, in the opinion
> of the UA.  In standard browsers it would match as soon as the user
> triggered a change event, but the exact details of when it matches are
> up to the UA.
>

It seems necessary to define "significantly interacted with".

Garrett

Received on Thursday, 24 September 2009 05:31:53 UTC