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

Prevent invalid 'required' field being saved to model if its already set... #26

Merged
merged 2 commits into from
Oct 3, 2012
Merged

Prevent invalid 'required' field being saved to model if its already set... #26

merged 2 commits into from
Oct 3, 2012

Conversation

akhabibullina
Copy link
Contributor

Current implementation enables invalid required field value being saved to model if its already set value is not undefined.

1 var currentValue = model.get(attributeName);
2 var isNotAlreadySet = _ .isUndefined(currentValue);
3 var isNotBeingSet = _ .isUndefined(valueToSet);
4 if (_.isNull(valueToSet) || valueToSet === "" || (isNotBeingSet && isNotAlreadySet)) {

This means, attempt to save 'undefined' value will be successful despite the fact error will be eventually generated and shown.

This very small fix will help to overcome the problem and make validation for required field work as expected.

@nealstewart
Copy link
Owner

modify/add tests and we're good.

@akhabibullina
Copy link
Contributor Author

I added check to be sure attempt to save 'undefined' value will result in appropriate error and won't be saved for required field.

nealstewart pushed a commit that referenced this pull request Oct 3, 2012
…d_value

Prevent invalid 'required' field being saved to model if its already set...
@nealstewart nealstewart merged commit 96a9c3b into nealstewart:master Oct 3, 2012
@akhabibullina
Copy link
Contributor Author

Thanks for merge.

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

Successfully merging this pull request may close these issues.

2 participants