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.
If you want to support that case I'd make a tiny directive for form field.
I strongly dislike the class based search. As you say, it mixes style and
function.
On Aug 18, 2014 2:26 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)
>
> This assumes the input is always going to be a child of the form-field.
> The original code (inputEl.parents(".form-field").first()) is far more
> robust and will catch cases where the input has been wrapped in other
> elements.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/hypothesis/h/pull/1405/files#r16343870>.
>