I am using angular version 1.5.5 and recently upgraded to angular material 1.1.0. After upgrading I started facing few issues in ng messages. Initially ng messages was not displaying. I fixed it by adding below class by referring to git issue
md-input-container .md-input-message-animation:not(.ng-animate) {
opacity: 1;
margin-top: 0px;
}
Now same ng message is displaying multiple times.
<div class="inputbox-area" ng-form='subForm'>
<md-input-container class="md-block" ng-repeat="item in dg.inputArr">
<label>Level {{$index+1}}</label>
<input md-maxlength="32" maxlength="32" ng-change="dg.showErrors = false" name="{{item.Level}}" required ng-model="item.Name" ng-pattern="/^[-a-zA-Z0-9,._' ]*$/" type="text">
<div ng-messages="subForm[$index+1].$error" ng-if="dg.showErrors">
<div ng-message="required">Level {{$index+1}} is mandatory</div>
<div ng-message="md-maxlength">should be less than 32 characters long.</div>
<div ng-message="duplicate">Level {{$index+1}} is a duplicate name</div>
<div ng-message="pattern" class="my-message">Level {{$index+1}} is an invalid name</div>
</div>
</md-input-container>
</div>
Any suggestions where I am going wrong?
<div class="inputbox-area" ng-form='subForm'>
<md-input-container class="md-block" ng-repeat="item in dg.inputArr">
<label>Level {{$index+1}}</label>
<input md-maxlength="32" maxlength="32" ng-model-options="{ updateOn: 'submit' }" ng-change="dg.showErrors = false" name="{{item.Level}}" required ng-model="item.Name" ng-pattern="/^[-a-zA-Z0-9,._' ]*$/" type="text">
<div ng-messages="subForm[$index+1].$error" ng-if="dg.showErrors">
<div ng-message="required">Level {{$index+1}} is mandatory</div>
<div ng-message="md-maxlength">should be less than 32 characters long.</div>
<div ng-message="duplicate">Level {{$index+1}} is a duplicate name</div>
<div ng-message="pattern" class="my-message">Level {{$index+1}} is an invalid name</div>
</div>
</md-input-container>
</div>
The problem is your model getting updated each time an event fires so add ng-model-options="{ updateOn: 'submit' }" in your input box this will fire only when you submit that form
Im not 100% sure, but i think ng-messages should refer to the name of the input field like this:
ng-messages="subForm.{{item.Level}}.$error"
I dont know if this sintax is gonna work, but try it out and see if it does.
Related
Below is my code to show a text box and a button next to it for uploading a file using ng-file-upload. I am trying to show the respective validation error messages like mandatory field,file size limit and acceptable file types. I am able to successfully show the error messages for required field and file size but not for acceptable file types which means
<div ng-message="accept">File format must be {{ vm.fileaccept }}</div> is not working. I am setting vm.fileaccept in the controller as vm.fileaccept = '.pdf,image/*';
<form name="uploadForm" ng-submit="vm.submitFile()" novalidate>
<div layout="row" flex="100">
<div layout="column" flex="95">
<md-input-container>
<input type="text" readonly name="filename"
class="form-control" ng-model="vm.filename" required/>
<div class="errors"
ng-show="uploadForm.$submitted || uploadForm.filename.$dirty"
ng-messages="uploadForm.filename.$error">
<div ng-message="required">Required</div>
</div>
<div class="errors"
ng-show="uploadForm.file.$error"
ng-messages="uploadForm.file.$error">
<div ng-message="maxSize">File size cannot exceed 1MB</div>
<div ng-message="accept">File format must be {{ vm.fileaccept }}</div>
</div>
</md-input-container>
</div>
<div layout="column" flex="5">
<md-input-container>
<button
ngf-select="vm.selectFile($file, $invalidFiles)" ng-model="file"
name="file" ngf-accept="vm.fileaccept" ngf-pattern="vm.fileaccept"
ngf-min-height="100" ngf-max-size="1MB">
<i class="fa fa-folder-open-o"></i></button>
</md-input-container>
</div>
</div>
</form>
I don't know the reason exactly , the below change worked.
<div ng-message="accept">File format must be {{ vm.fileaccept }}</div>
to
<div ng-message="pattern">File format must be {{ vm.fileaccept }}</div>
I don't know why but I can't seem to display the content of ng-message for 'required'. I'm new to this, so please excuse if I'm missing something obvious!!
If I try to display {{studentForm.fName.$error}} it says blank.
Btw this is my first question on stackoverflow :)
EDIT:
Use form tag instead of md-form.
Seems like md-form is not a valid tag.
Additionally md-auto-hide="false" might me required under ng-messages tag.
see : https://github.com/angular/material/issues/6767
<div layout="row">
<div layout="column">
<md-form ng-model="student" name="studentForm" flex="90%">
<div layout="column" layout-padding>
<md-input-container class="md-block" flex>
<label for="firstName">firstName</label>
<input type="text" ng-model="student.firstName" name="fName" placeholder="firstName" required></input>
</md-input-container>
<div ng-messages="studentForm.fName.$error" role="alert">
<div ng-message="required">Required!!</div>
</div>
<md-datepicker name="DOB" ng-model="student.DOB" md-placeholder="Enter DOB" required valid>Enter DOB</md-datepicker>
<div ng-messages="studentForm.DOB.$error" role="alert">
<div ng-message="valid">The entered value is not a date!</div>
<div ng-message="required">This date is required!</div>
</div>
</div>
<md-button ng-click="submit()">Send your message</md-button>
</md-form>
</div>
</div>
Use form tag instead of md-form. Seems like md-form is not a valid tag. Additionally md-auto-hide="false" might me required under ng-messages tag. see : https://github.com/angular/material/issues/6767
I have a simple code :
<div class="row" ng-repeat="aDiagnosis in diagnosisListForPrescription">
<div class="col-md-4 padding-right-zero" id={{aDiagnosis.rowIndex}}>
<input class="form-control" name="aDiagnosisName" ng-model="aDiagnosis.Name" ng-disabled="true">
</div>
<div class="col-md-4 padding-right-zero form-group" show-errors id={{aDiagnosis.rowIndex}}>
<input class="form-control" name="aDiagnosisResult" ng-maxlength="200" ng-model="aDiagnosis.Result" />
<p class="help-block" ng-if="form.aDiagnosisResult.$error.maxlength">Too Large</p>
</div>
</div>
and use $scope.form.$valid to generate the error message.
But problem is since use ng-repeat every time it finds the same name and when i want to generate second list by clicking a button ,,first error message is gone and error-message now works on the second text (obviously).
So How can i generate error-message each and every time dynamically ,,so every text form in ng-repeat,it has it's own error-message.
You can generate dynamically name attribute of your inputs in ng-repeat. For example, you can put $index (or id of your objects or whatever you want) to generate unique name for your inputs.
<div class="row" ng-repeat="aDiagnosis in diagnosisListForPrescription">
<div class="col-md-4 padding-right-zero" id={{aDiagnosis.rowIndex}}>
<input class="form-control" name="aDiagnosisName-{{$index}}" ng-model="aDiagnosis.Name" ng-disabled="true">
</div>
<div class="col-md-4 padding-right-zero form-group" show-errors id={{aDiagnosis.rowIndex}}>
<input class="form-control" name="aDiagnosisResult-{{$index}}" ng-maxlength="200" ng-model="aDiagnosis.Result" />
<p class="help-block" ng-if="form['aDiagnosisResult-' + $index].$error.maxlength">Too Large</p>
</div>
</div>
Example on plunker.
All,
I am working on an AngularJS form and am trying to see how the ng-messages directive works with ng-messages-multiple. I can't seem to get it to pick up multiple errors. I expect to see both the required and minimum errors at the same time but for some reason I only see required, then minimum. I posted the HTML below. I have the ng-messages included using bower, the script call in my index.html page, and I am injecting into my app.js module as required.
I am using AngularJS v1.3.2 in this project.
<div class="panel panel-default">
<div class="panel-heading">
<h1>Validation Test Form</h1>
</div>
<div class="panel-body">
<form class="form" name="form" role="form" ng-submit="submit(form)">
<div class="row">
<div class="form-group" show-errors>
<label for="name">Name:</label>
<input
class="form-control"
type="text"
name="name"
ng-model="formModel.name"
minlength="5"
required/>
<div ng-messages="form.name.$error" ng-messages-multiple class="has-error">
<div ng-message="required">Required!</div>
<div ng-message="minlength">Minimum length is 5</div>
</div>
</div>
</div>
<div class="row">
<div class="form-group">
<button class="btn btn-success" type="submit">Save</button>
</div>
</div>
</form>
</div>
<div class="panel-footer">
{{formError}}
</div>
</div>
Try to use ng-minlength instead minlength
<input
class="form-control"
type="text"
name="name"
ng-model="formModel.name"
ng-minlength="5"
required/>
instead
<input
class="form-control"
type="text"
name="name"
ng-model="formModel.name"
minlength="5"
required/>
EDIT
It is normal behaviour for ng-minlength directive, this directive validate only when we have not 0 size of input, entered a value it must be at least 5 characters long, but it's ok to leave the field empty, and, unfortunately, in anyway you don't achieve, that you want. I offer you to create your custom directive or see in direction ng-pattern directive with need behaviour, if you very want that showing two message.
I'm working with Bootstrap 3 and the AngularJS UI.
I've integrated a Datepicker into an accordion, but it doesn't show over/outside the accordion body in itself.
I found a reference on the same problem and the solution (here), but it's with Bootstrap 2.3.1 and after trying the .collapse{ position:inherited; } solution on my code and trying to override the z-index, it's still not working.
Here's a Plunker with the problem on 2.3.1 so you can understand the problem, and my current code. Any ideas on what's causing the problem?
<div class="row ix-advanced">
<div class="panel-group col-md-12" id="accordion">
<div class="panel panel-default">
<div id="advancedSearch" class="panel-collapse collapse">
<div class="panel-body">
<form class="form-inline" role="form">
<div class="form-group col-md-1">
<label><?php echo _t('Date')?></label><br />
<input type="text" class="form-control input-sm" datepicker-popup="dd-MM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" placeholder="<?php echo _t('From')?>"/>
</div>
<div class="form-group col-md-1">
<label><?php echo _t('To')?></label><br />
<input type="text" class="form-control input-sm" placeholder="<?php echo _t('To')?>">
</div>
</form>
</div>
</div>
</div>
</div>
</div>
in your css, overwrite bootstrap's panel overflow: hidden property with
.panel-group .panel {
overflow: inherit;
}
The solution is to add to the last datepicker the following attribute:
datepicker-append-to-body="true"
You may also want to change the attribute "open" to "is-open".
You can see the results in the updated plunker.
I've updated the plunker to the latest versions and it seems to work fine.
My problem though is that if you layout your controls with the grid system, then the popup is clipped to fit the row and col-
-Stephen