aurelia / validation

A validation plugin for Aurelia.
MIT License
132 stars 128 forks source link

Validation not working with if.bind. #218

Closed jkesselring-zz closed 8 years ago

jkesselring-zz commented 8 years ago

Validation does not function when interacting with if.bindings. The initial elements are bound to correctly and validate the first However the elements that are not yet in the DOM are not bound to when they are loaded into the DOM.

There should a means of binding to these elements for validation.

this.obj = { 
  foo: '',
  bar: '',
  baz: '',
  foobar: false;
};

{
  validation.on(this.obj)
    .ensure('foo')
      .isNotEmpty()
    .ensure('bar')
      .isNotEmpty();
}

loadMoreFields(){
  this.obj.foobar = true;
}

As expected an input as such works.

<input type='text' validate='foo'  value.bind='obj.baz'>

An input as below does not work.

<div if.bind='obj.foobar'>
  <input validate='bar' value.bind='obj.bar' />
</div>
plwalters commented 8 years ago

Sorry I don't quite follow - you don't have a value binding in there anywhere. When you say it doesn't work could you be more descriptive so I can reproduce what you mean?

jkesselring-zz commented 8 years ago

Sorry. The issue that I am having is that the fields in the form that are not behind an if.bind are validated correctly. However, the form fields behind the if.bind do not validate.

When the page loads initially any field that is there regardless of the if bind are validating as one would expect. When the user causes the if binding to be true then the form is given further fields. These fields that were loaded after into the DOM are not validating. Even as the validation and fields are bound to the object that I am validating on.

lor3 commented 8 years ago

Think I have found the same problem as this.. If you take the following form :

<form validate.bind="validation">
    <div if.bind="showForename">
        <div class="form-group">
            <input type="text" value.bind="Forename" />
        </div>
    </div>
    <div class="form-group">
        <input type="text" value.bind="Surname" />
    </div>
</form>

For me, when Forename gets displayed, even though validation does work the validationViewStrategy doesn't add the attributes to the form. I'm using my own strategy here and prepareElement / updateElement are never called for the newly created/bound Forename element.

jkesselring-zz commented 8 years ago

@PWKad With a potential rewrite will this issue be solved?

plwalters commented 8 years ago

Thanks for submitting this / commenting on this. At this time we are closing this because we have completely re-written and are deprecating the previous feature set. If you feel this should be re-opened please feel free to review this blog post and submit either again on this repository, or on the new validatejs bridge repository

Thanks again!