aurelia / validation

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

can't validate multiple members of an object when composed #116

Closed mbroadst closed 8 years ago

mbroadst commented 9 years ago

I've been writing my own validation strategy, and discovered that updateElement and prepareElement are initially called for both of the following properties, but no subsequent updateElement is called for the second property:

import {inject} from 'aurelia-framework';
import {Validation} from 'aurelia-validation';

@inject(Validation)
export class Test {
  record = {}
  constructor(validation) {
    this.validation = validation.on(this)
      .ensure('record.blah')
            .isNotEmpty()
            .hasMinLength(3)
            .hasMaxLength(10)
      .ensure('record.halb')
            .isNotEmpty()
            .hasMinLength(3)
            .hasMaxLength(10);
  }
}
mbroadst commented 9 years ago

any ideas on what's going on here?

mbroadst commented 9 years ago

Okay this was initially improperly named, because you:

My particular case is a little bit more involved. I've got a "dialog fragment" which I am composing in a top level dialog, which conveys data through the fragments activate method. When the bound object comes in that way, validation only works on the first nested reference to the data.

Here is a plunker that shows this behavior: http://plnkr.co/edit/HS0SurEzHDoxyseplx08

mbroadst commented 9 years ago

It looks like the issue is because the dialog-fragment doesn't have a default assignment for record when its created (it was only being set by the params passed into activate). If you add record = {} after export class DialogFragment { in dialog-fragment.js I get the update events

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!