is possible use ng-show based on 2 conditions, guess in case 3 conditions. know can function or directive when loading view , propagating data dynamically generated form elements using ng-repeat. easier @ point add condition ng-show actual input not marked invalid , form still submit valid. when form first loads last element in dynamically created form displays error message if invalid until $touched = true , $veiwvalue changes.
to keep simple, ng-show looks this:
<div class="list-help-block" ng-messages="emails_form.email.$error" ng-show="emails_form.email.$dirty || emails_form.email.$invalid"> <div ng-messages-include="/app/views/messages.html" ></div> </div>
this displays error messages fine on invalid entry , on error when form submitted. displays error message (which there shouldn't error) when form loads. , on last input dynamically added form.
what this:
ng-show="emails_form.email.$dirty || emails_form.email.$invalid not mails_form.email.$pristine"
i don't know if that's possible or if may possible call function fix validation once view loaded , data has been added model. suggestions?
here's whole section used this:
<div ng-repeat="emails in info.instructor.instructor_emails"> <ng-form name="emails_form" novalidate> <div class="input-group"> <span class="input-group-label"> <span ng-show="info.instructor.instructor_emails.length==1">@</span> <span ng-show="info.instructor.instructor_emails.length>=2"><a ng-click="updateremoveemail($index)"><i class="fi-x"></i></a></span> </span> <input ng-class="{ notvalid: submitted && emails_form.email.$invalid }"type="email" placeholder="jane.doe@example.com" name="email" ng-model="emails.email" ng-required="info.instructor.instructor_emails.length>=2"/> </div> <div class="list-help-block" ng-messages="emails_form.email.$error" ng-if="!emails_form.email.$pristine && (emails_form.email.$dirty || emails_form.email.$invalid)"> <div ng-messages-include="/app/views/messages.html" ></div> </div>
as suggestion, i'd recommend use ngif
instead of ngshow
practice.
as per understood not
, should work:
ng-if="!emails_form.email.$pristine && (emails_form.email.$dirty || emails_form.email.$invalid)"
Comments
Post a Comment