angularjs - Form validation with modals in Angular -


i have form inside modal pop up. trying run form validation on inputs after user attempts submit form. far, i'm struggling make things work.

in view, have following (sorry if there syntax errors, i'm converting jade on fly):

<script type="text/ng-template", id="modalvideonew">   <div class="ngdialog-message">     <form class="form-horizontal" ng-submit="submitform()" novalidate name="newvideoform">    ...       <div class="form-group">       <label> title </label>       <div class="col-sm-8">         <input type="text" name="title", required='', ng-model="newvideoform.title">         <span class="text-danger" ng-show="validateinput('newvideoform.title', 'required')"> field required</span>      </div>    </div>  </div> </script> 

and in controller, i'm calling ng-dialog pop up, have this:

         $scope.newvideo = function() {            ngdialog.openconfirm({            template: 'modalvideonew',            classname: 'ngdialog-theme-default',            scope: $scope          }).then(function() {            $scope.validateinput = function(name, type) {              var input = $scope.newvideoform[name];            return (input.$dirty || $scope.submitted) && input.$error[type];         };           var newvideo = $scope.newvideoform;         ... 

right now, still able submit form, once open see 'this field required' error message. also, input pre-filled [object, object] instead of empty text input box.

a way of cleaning model work using model var belongs parent controller , cleaning in callback. check out how template has attached parent controller's var formdata.

check this out

so validation, recommend have own controller in it, no matter how code have. helps keeping concepts of modularization , better control on scopes. way facilitate lot when validating.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -