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

Can't access map instance on validators when value is set #41

Open
m-mujica opened this issue Nov 21, 2016 · 0 comments
Open

Can't access map instance on validators when value is set #41

m-mujica opened this issue Nov 21, 2016 · 0 comments

Comments

@m-mujica
Copy link
Contributor

m-mujica commented Nov 21, 2016

Let's say you want to conditionally validate the presence of a can/map property

I'd expect I could write something like

Map.extend({
  define: {
    foo: {
      validate: {
        presence(value, attributes, attributeName) {
          return this.attr('mySpecialProperty') === mySpecialValue;
      }
    }
  }
});

See ansman/validate.js#33

The problem with that is:

  1. this is null inside the presence function
  2. The attributes argument is an object with the map instance properties when mapInstance.validate() is called, but when mySpecialProperty is set, attributes no longer contains the map properties, so we can't rely on that

Is there a way to implement conditional validation like this currently? what am I missing?

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

1 participant