Skip to content

Validating specific values without changing the object #55

Closed
berzniz opened this Issue Jun 26, 2012 · 3 comments

2 participants

@berzniz
berzniz commented Jun 26, 2012

I'd like to be able to check if a value can be set to an attribute without actually setting the attribute.

Example usage:
When a user fills a form, I want to check (on each key press) if the input is valid - without changing the model. The model should change when the input's change event happens (on blur).

To allow for this I added the following code to the mixin object:

validateValue: function(value, attr) {
  return validateAttr(this, this.validation, attr, value, this.toJSON());
}

and now I can call it like this:

myModel.validateValue('http://google.com', 'website');

Do you think such a method would be useful for more users of the backbone.validation lib?

@thedersen
Owner

I like it!

I will swap the order of the parameters you suggested to be more in line with Backbone, and I think I would rename the method to preValidate(attr, value)

@berzniz
berzniz commented Jul 16, 2012

Thanks!

You're doing a great job with backbone.validation, it really helps me a lot.

@thedersen
Owner

Thanks for the kind words! A new version will hopefully be up in just a few days.

@thedersen thedersen added a commit that closed this issue Jul 19, 2012
@thedersen Added preValidate(attr, value) that can be used to preview if a value…
… is valid or not. Returns error message when not valid, otherwise nothing. Closes #55
503b74a
@thedersen thedersen closed this in 503b74a Jul 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.