Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behavior with .on and validationRules #312

Closed
nano2nd opened this issue Sep 2, 2016 · 2 comments
Closed

Odd behavior with .on and validationRules #312

nano2nd opened this issue Sep 2, 2016 · 2 comments

Comments

@nano2nd
Copy link

nano2nd commented Sep 2, 2016

I'm submitting a bug report

  • Library Version:
    0.12.2

  • Operating System:
    Windows 10

  • Node Version:
    5.4.1

  • NPM Version:
    3.3.12

  • JSPM Version
    JSPM 0.16.32

  • Browser:
    all

  • Language:
    TypeScript 1.8

Current behavior:
When Adding properties or rather object via the "entity validation" methodology, there seems to be an interesting scenario where my entities will not validate unless I call validate() in the form controller.validate({ object: person }).

For instance, if I have this:

ValidationRules
.ensure('firstName').required()
.ensure('lastName').required()
.ensureObject().satisfies((e) => {
return _.every(e.workDates, (d) => d.StartDate != null);
})
.withMessage('All dates must have a start date')
.on(this.employee)

this.controller.addObject(this.employee.workDates);

and call controller.validate() with no arguments, everything will validate except the workDates object.

On the other hand, if I call controller.validate({object: this.employee}), itworks as expected and the employee.workDates object validates as expected.

This seems like a bug to me, but maybe this is expected behavior for some reason?

Thanks

@jsobell
Copy link
Contributor

jsobell commented Sep 4, 2016

Shouldn't that say

this.controller.addObject(this.employee);

?

@jdanyow
Copy link
Contributor

jdanyow commented Sep 4, 2016

With ensure(propertyName), we know we need to validate rules associated with the property when a binding to the property changes.

With ensureObject() we don't know which properties should cause which rules to validate, so any rules applied using ensureObject() will only be validated when you call controller.validate() manually.

We're looking into an enhancement that would allow you to define which property changes should trigger custom rule validation in #279.

A quick work-around for you might be to do something like this:

<div change.delegate="controller.validate()">
  <!-- bindings to workDates...StartDate -->
</div>

Any DOM change events that fire due to the user editing start dates would trigger the controller to validate. You could fine-tune this by passing an instruction to the validate method specifying the precise object and rules you want to validate (see docs for more info).

Linking this issue to #279 and closing.

@jdanyow jdanyow closed this as completed Sep 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants