AngularJs Form Validation For Edit Page





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have used the error form validation in the addnewstudent page as below and it's working fine.



  <td>
<input limit-to="50" type="email" name="input" ng-model="Email" />
<span style="display:none">{{ emailValid = !!myForm.$error.email}}</span>
<span ng-class="customStyle.colorClass">
{{EmailValidation }}
</span>
</td>


Same approach I used for my edit page as like below, but Iam not able to get the bool value of "!!myForm.$error".



my Edit page



 <td>
<input limit-to="50" type="text" ng-model="Student.email" />
<span style="display:none">{{ emailValid = !!myForm.$error.Student.email}}
</span>
<span>
{{EmailValidation }}
</span>
</td>


My JS,



 $scope.save = function () {

if ($scope.emailValid || $scope.Student.email=='') {
$scope.EmailValidation = 'Not a valid email (ex: me@example.com)';
return;
}
else {
$scope.EmailValidation = '';
}
.......
.......


Where I did go wrong on my edit page?










share|improve this question


















  • 1





    What is your ultimate goal ? check whether input value is a email or not ?

    – Ebin Manuval
    Nov 25 '18 at 8:03


















1















I have used the error form validation in the addnewstudent page as below and it's working fine.



  <td>
<input limit-to="50" type="email" name="input" ng-model="Email" />
<span style="display:none">{{ emailValid = !!myForm.$error.email}}</span>
<span ng-class="customStyle.colorClass">
{{EmailValidation }}
</span>
</td>


Same approach I used for my edit page as like below, but Iam not able to get the bool value of "!!myForm.$error".



my Edit page



 <td>
<input limit-to="50" type="text" ng-model="Student.email" />
<span style="display:none">{{ emailValid = !!myForm.$error.Student.email}}
</span>
<span>
{{EmailValidation }}
</span>
</td>


My JS,



 $scope.save = function () {

if ($scope.emailValid || $scope.Student.email=='') {
$scope.EmailValidation = 'Not a valid email (ex: me@example.com)';
return;
}
else {
$scope.EmailValidation = '';
}
.......
.......


Where I did go wrong on my edit page?










share|improve this question


















  • 1





    What is your ultimate goal ? check whether input value is a email or not ?

    – Ebin Manuval
    Nov 25 '18 at 8:03














1












1








1








I have used the error form validation in the addnewstudent page as below and it's working fine.



  <td>
<input limit-to="50" type="email" name="input" ng-model="Email" />
<span style="display:none">{{ emailValid = !!myForm.$error.email}}</span>
<span ng-class="customStyle.colorClass">
{{EmailValidation }}
</span>
</td>


Same approach I used for my edit page as like below, but Iam not able to get the bool value of "!!myForm.$error".



my Edit page



 <td>
<input limit-to="50" type="text" ng-model="Student.email" />
<span style="display:none">{{ emailValid = !!myForm.$error.Student.email}}
</span>
<span>
{{EmailValidation }}
</span>
</td>


My JS,



 $scope.save = function () {

if ($scope.emailValid || $scope.Student.email=='') {
$scope.EmailValidation = 'Not a valid email (ex: me@example.com)';
return;
}
else {
$scope.EmailValidation = '';
}
.......
.......


Where I did go wrong on my edit page?










share|improve this question














I have used the error form validation in the addnewstudent page as below and it's working fine.



  <td>
<input limit-to="50" type="email" name="input" ng-model="Email" />
<span style="display:none">{{ emailValid = !!myForm.$error.email}}</span>
<span ng-class="customStyle.colorClass">
{{EmailValidation }}
</span>
</td>


Same approach I used for my edit page as like below, but Iam not able to get the bool value of "!!myForm.$error".



my Edit page



 <td>
<input limit-to="50" type="text" ng-model="Student.email" />
<span style="display:none">{{ emailValid = !!myForm.$error.Student.email}}
</span>
<span>
{{EmailValidation }}
</span>
</td>


My JS,



 $scope.save = function () {

if ($scope.emailValid || $scope.Student.email=='') {
$scope.EmailValidation = 'Not a valid email (ex: me@example.com)';
return;
}
else {
$scope.EmailValidation = '';
}
.......
.......


Where I did go wrong on my edit page?







javascript angularjs






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 6:36









Md AslamMd Aslam

2562828




2562828








  • 1





    What is your ultimate goal ? check whether input value is a email or not ?

    – Ebin Manuval
    Nov 25 '18 at 8:03














  • 1





    What is your ultimate goal ? check whether input value is a email or not ?

    – Ebin Manuval
    Nov 25 '18 at 8:03








1




1





What is your ultimate goal ? check whether input value is a email or not ?

– Ebin Manuval
Nov 25 '18 at 8:03





What is your ultimate goal ? check whether input value is a email or not ?

– Ebin Manuval
Nov 25 '18 at 8:03












1 Answer
1






active

oldest

votes


















2














To validate a form input in angularjs there should be name attribute for that input and form also.






angular.module('sampleApp', )
.controller('myCtrl', function($scope) {
$scope.Student = {}
})

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="sampleApp" ng-controller="myCtrl" >
<form name="myForm" novalidate>
<input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
<div ng-show="myForm.$submitted || myForm.email.$touched">
<span ng-show="myForm.email.$error.required">Tell us your email.</span>
<span ng-show="myForm.email.$error.email">This is not a valid email.</span>
</div>
<button>Submit</button>
</form>
</div>





Above code will check for non empty valid email, which is done by required,type="email" attributes.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465241%2fangularjs-form-validation-for-edit-page%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    To validate a form input in angularjs there should be name attribute for that input and form also.






    angular.module('sampleApp', )
    .controller('myCtrl', function($scope) {
    $scope.Student = {}
    })

    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
    <div ng-app="sampleApp" ng-controller="myCtrl" >
    <form name="myForm" novalidate>
    <input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
    <div ng-show="myForm.$submitted || myForm.email.$touched">
    <span ng-show="myForm.email.$error.required">Tell us your email.</span>
    <span ng-show="myForm.email.$error.email">This is not a valid email.</span>
    </div>
    <button>Submit</button>
    </form>
    </div>





    Above code will check for non empty valid email, which is done by required,type="email" attributes.






    share|improve this answer




























      2














      To validate a form input in angularjs there should be name attribute for that input and form also.






      angular.module('sampleApp', )
      .controller('myCtrl', function($scope) {
      $scope.Student = {}
      })

      <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
      <div ng-app="sampleApp" ng-controller="myCtrl" >
      <form name="myForm" novalidate>
      <input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
      <div ng-show="myForm.$submitted || myForm.email.$touched">
      <span ng-show="myForm.email.$error.required">Tell us your email.</span>
      <span ng-show="myForm.email.$error.email">This is not a valid email.</span>
      </div>
      <button>Submit</button>
      </form>
      </div>





      Above code will check for non empty valid email, which is done by required,type="email" attributes.






      share|improve this answer


























        2












        2








        2







        To validate a form input in angularjs there should be name attribute for that input and form also.






        angular.module('sampleApp', )
        .controller('myCtrl', function($scope) {
        $scope.Student = {}
        })

        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
        <div ng-app="sampleApp" ng-controller="myCtrl" >
        <form name="myForm" novalidate>
        <input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
        <div ng-show="myForm.$submitted || myForm.email.$touched">
        <span ng-show="myForm.email.$error.required">Tell us your email.</span>
        <span ng-show="myForm.email.$error.email">This is not a valid email.</span>
        </div>
        <button>Submit</button>
        </form>
        </div>





        Above code will check for non empty valid email, which is done by required,type="email" attributes.






        share|improve this answer













        To validate a form input in angularjs there should be name attribute for that input and form also.






        angular.module('sampleApp', )
        .controller('myCtrl', function($scope) {
        $scope.Student = {}
        })

        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
        <div ng-app="sampleApp" ng-controller="myCtrl" >
        <form name="myForm" novalidate>
        <input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
        <div ng-show="myForm.$submitted || myForm.email.$touched">
        <span ng-show="myForm.email.$error.required">Tell us your email.</span>
        <span ng-show="myForm.email.$error.email">This is not a valid email.</span>
        </div>
        <button>Submit</button>
        </form>
        </div>





        Above code will check for non empty valid email, which is done by required,type="email" attributes.






        angular.module('sampleApp', )
        .controller('myCtrl', function($scope) {
        $scope.Student = {}
        })

        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
        <div ng-app="sampleApp" ng-controller="myCtrl" >
        <form name="myForm" novalidate>
        <input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
        <div ng-show="myForm.$submitted || myForm.email.$touched">
        <span ng-show="myForm.email.$error.required">Tell us your email.</span>
        <span ng-show="myForm.email.$error.email">This is not a valid email.</span>
        </div>
        <button>Submit</button>
        </form>
        </div>





        angular.module('sampleApp', )
        .controller('myCtrl', function($scope) {
        $scope.Student = {}
        })

        <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
        <div ng-app="sampleApp" ng-controller="myCtrl" >
        <form name="myForm" novalidate>
        <input limit-to="50" type="email" ng-model="Student.email" name="email" required/>
        <div ng-show="myForm.$submitted || myForm.email.$touched">
        <span ng-show="myForm.email.$error.required">Tell us your email.</span>
        <span ng-show="myForm.email.$error.email">This is not a valid email.</span>
        </div>
        <button>Submit</button>
        </form>
        </div>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 8:22









        Ebin ManuvalEbin Manuval

        8201125




        8201125
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465241%2fangularjs-form-validation-for-edit-page%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings