Open warnero opened 10 years ago
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.
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.
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
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:
Any idea why adding forms.* in front would suddenly cause rc to stop validating things for me?