0

I have a simple form and i have to validate many input fields on ajax call.

Many of input fields are reusable so i have used directive for them.

<input name="UserName" 
       type="text" 
       user-name-unique 
       ng-model="UserName" 
       required 
/>

Directive function :

 elem.on('blur', function(evt) {
   scope.$apply(function() {
     var data = { 'username': elem.val() };
     var ajaxConfiguration = { method: 'POST', url: 'url', data: data };
     async(ajaxConfiguration).success(function(data, status, headers, config) {
       ctrl.$setValidity('userNameUnique', !data.IsSuccess);
     });
   });
 });

Similarly i have many directives which validates the input using ajax call.

How to make my submit function to wait for all my ajax requests to complete?

1 Answer 1

1

create a directive that your submit button can track, and then slap a disabled directive on your submit button that will only update once your custom directive fields are evaluated to true:

<input name="UserName" 
       type="text" 
       user-name-unique 
       ng-model="UserName" 
       required 
       validate="process()" //retun true/false, processed whenever value changes
/>


<form>
    <button type="submit" disabled>Submit</button>
</form>

Then create a listener for when the input updates, and check it's validated state

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.