1

I have a form which need to show validation error popup window message if clicked submit. Here is my form.

 <form ng-submit="register(user)">
<div class="list">
  <label class="item item-input">
    <input type="text" placeholder="First Name" ng-model="user.first" >
  </label>
  <label class="item item-input">
    <input type="text" placeholder="Last Name" ng-model="user.last">
  </label>
</div>
<button class="button button-positive">
  button-positive
</button>
</form>

Here is the validation controller file

 angular.module('starter.controllers',[])

.controller('DashCtrl', function($scope,$ionicPopup,Friends) {


    $scope.register=function(user){
      if(!user.first){ $ionicPopup.alert({
                       title: 'First Name Required!',
                       template:'Firstname'
                       });
      }else{
            if(!user.last){
                           $ionicPopup.alert({
                           title: 'Last Name Required!',
                           template:'Lastname'
                           });
              }else {


                        Friends.setall(user).then(function(msg){
                             console.log("From server"+msg.data);

                          });
              }

        }
    }

})

Validation works normally when start making changes. But it doesn't show any error messages If clicked submit without entering anything.How can i achieve this? also i want to show loading screen for the server request and it is dissmissed when the server request is complete.I am using ionicframework,and i know ionic.loading is used for this but How can i properly used this in my code?.Please help.

2
  • Why not let Angular do the validation directly on the form rather than having the logic in your controller and a popup? If its a required field than put the HTML5 attribute on it required. Else you can check to see if the form is "$dirty" docs.angularjs.org/guide/forms Commented Sep 9, 2014 at 16:25
  • I worked on mobile apps and i think popup message is better for error messages rather than text because user can easily notify the errors. Commented Sep 9, 2014 at 16:32

1 Answer 1

3

For the validation part of your question, I would just check for user along with user.firstname:

if(!user || !user.first){ $ionicPopup.alert({
  title: 'First Name Required!',
  template:'Firstname'
});

and you can use $ionicLoading, after injecting it into the controller, like this:

else {
  $ionicLoading.show({ template: 'Loading...' });
  Friends.setall(user).then(function(msg){
    console.log("From server"+msg.data);
    $ionicLoading.hide();
  });
}
Sign up to request clarification or add additional context in comments.

1 Comment

Can you give an answer for this? (stackoverflow.com/questions/25831459/…)

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.