Simplify form error input handling

The form-input class now has the directive responsible for setting
the error classes. It watches its scope and sets the errors only
if the model is defined. This guard against undefined keeps the
error class from being set until validation passes, which is the
case when local validation succeeds, but in a digest cycle after the
server returns a failure notification this will trigger the error
class.
    
The form-validate directive is now just a controller forform-input to
register a callback to force error checking on submit.
Yep.

We could probably just use the descendent selectors to style the inputs and
set the class only on the field div.

In that case, the controller could just export toggleClass. It's just a
small lifting of that function up to a controller on the field that's
needed.

I think the result is pretty attractive.
On Aug 18, 2014 2:54 AM, "Aron Carroll" <notifications@github.com> wrote:

> In h/static/scripts/directives.coffee:
>
> >
> > -      if field.$valid or field.$pristine
> > -        toggleClass(field, addClass: false)
> > -      else if field.$dirty
> > -        toggleClass(field, addClass: true)
> > +    toggleClass = (addClass) ->
> > +      elem.toggleClass(errorClassName, addClass)
> > +      elem.parent().toggleClass(errorClassName, addClass)
>
> Touché. So then what this directive would be similar to the formValidator
> in that it would be required by the formInput and have add/remove class
> methods?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/hypothesis/h/pull/1405/files#r16345015>.
>