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

Using this technique (forms.formName) so I can call setPristine now validation fails #13

Open
warnero opened this issue Oct 21, 2014 · 3 comments

Comments

@warnero
Copy link

warnero commented Oct 21, 2014

Ok, here's the technique I'm using
http://jsfiddle.net/zqS79/

Which recommends setting a scope variable called forms in controller so that when it gets set in template I have access to it to set pristine (otherwise $scope.formName is undefined).

When I do that all my validation using rc seems to no longer work. Here is an example:

Name Name Required
...

Any idea why adding forms.* in front would suddenly cause rc to stop validating things for me?

@warnero
Copy link
Author

warnero commented Oct 21, 2014

Ah, finally figured it out. Needed to do this instead:
`rc['forms.inviteForm'].needsAttention(forms.inviteForm.email)
and this works :). Might be good to add this to docs or allow first form somehow.

@warnero
Copy link
Author

warnero commented Oct 21, 2014

Hmm, and back to the beginning apparently. What I'm trying to do is to reuse the form after submission. Immediately after submission I call $setPristine() on the form which works, but the form fields still show that there are validation errors even though they haven't been touched yet.

Any help is greatly appreciated.

@robertbarfield
Copy link

I found a fix that worked for me.

For Submit : I modified the following function to reset the form on submit completion:

this.setSubmitComplete = function (success, data) {
angular.forEach(submitCompleteHandlers, function (handler) {
handler({ 'success': success, 'data': data });
});
formController.$setPristine();
this.attempted = false;
};


For Cancel : I added the following function right above the this.needsAttention function:

this.reset = function() {
formController.$setPristine();
this.attempted = false;
};


Then : I added the rc.form to my cancel function in the HTML view

< button class="btn" id="btnCancel" type="button" ng-click="cancelForm(rc.my_info_form)" >
Cancel
</ button >


Last : I called the directives reset function from my cancel function

$scope.cancelForm = function (form) {
if(form){
form.reset();
}
}


Hope this helps anyone in the same situation.

Thanks,
RGB

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

2 participants