Skip to content

Commit 36d9f07

Browse files
Adding doc and examples for uiValidate
1 parent aa87f7b commit 36d9f07

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

index.html

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<li><a scrollto href="#directives-keypress">Keypress</a></li>
5454
<li><a scrollto href="#directives-mask">Mask</a></li>
5555
<li><a scrollto href="#directives-if">If</a></li>
56+
<li><a scrollto href="#directives-validate">Validate</a></li>
5657
<li><a scrollto href="#directives-reset">Reset</a></li>
5758
<li><a scrollto href="#directives-animate">Animate</a></li>
5859
<li><a scrollto href="#directives-modal">Modal</a></li>
@@ -156,7 +157,7 @@ <h3>How?</h3>
156157
&lt;script&gt;
157158
myModule.value(&#x27;ui.config&#x27;, {
158159
// The ui-jq directive namespace
159-
jq: {
160+
jq: {
160161
// The qtip namespace
161162
qtip: {
162163
// qTip options. This object will be used as the defaults
@@ -217,7 +218,7 @@ <h3>How?</h3>
217218
</div>
218219
</div>
219220
</section>
220-
221+
221222
<section id="directives-map" ng-controller="MapCtrl">
222223
<div class="page-header">
223224
<h1>Google Maps</h1>
@@ -234,21 +235,21 @@ <h4>Click to add a marker!</h4>
234235
</a>
235236
</li>
236237
</ul>
237-
238+
238239
<!-- this is the confusing part. we have to point the map marker directive
239240
at an existing google.maps.Marker object, so it can hook up events -->
240241
<div ng-repeat="marker in myMarkers" ui-map-marker="myMarkers[$index]"
241242
ui-event="{'map-click': 'openMarkerInfo(marker)'}">
242243
</div>
243-
244+
244245
<div ui-map-info-window="myInfoWindow">
245246
<h1>Marker</h1>
246247
Lat: <input ng-model="currentMarkerLat">, Lng: <input ng-model="currentMarkerLng">
247248
<a class="btn btn-primary" ng-click="setMarkerPosition(currentMarker, currentMarkerLat, currentMarkerLng)">Set Position</a>
248249
</div>
249250
</div>
250251
<div ui-map="myMap" class="span8 map"
251-
ui-event="{'map-click': 'addMarker($event)', 'map-zoom_changed': 'setZoomMessage(myMap.getZoom())' }"
252+
ui-event="{'map-click': 'addMarker($event)', 'map-zoom_changed': 'setZoomMessage(myMap.getZoom())' }"
252253
ui-options="mapOptions">
253254
</div>
254255
</div>
@@ -277,7 +278,7 @@ <h3>How?</h3>
277278
&lt;/div&gt;
278279

279280
&lt;div ui-map=&quot;myMap&quot; class=&quot;map&quot;
280-
ui-event=&quot;{&#x27;map-click&#x27;: &#x27;addMarker($event)&#x27;, &#x27;map-zoom_changed&#x27;: &#x27;setZoomMessage(myMap.getZoom())&#x27; }&quot;
281+
ui-event=&quot;{&#x27;map-click&#x27;: &#x27;addMarker($event)&#x27;, &#x27;map-zoom_changed&#x27;: &#x27;setZoomMessage(myMap.getZoom())&#x27; }&quot;
281282
ui-options=&quot;mapOptions&quot;&gt;
282283
&lt;/div&gt;
283284

@@ -288,7 +289,7 @@ <h3>How?</h3>
288289
center: new google.maps.LatLng(35.784, -78.670),
289290
zoom: 15,
290291
mapTypeId: google.maps.MapTypeId.ROADMAP
291-
};
292+
};
292293

293294
$scope.addMarker = function($event) {
294295
$scope.myMarkers.push(new google.maps.Marker({
@@ -333,13 +334,13 @@ <h3>What?</h3>
333334
<p>Calendar picker with ng-model integration</p>
334335
<div class="well">
335336
<ng-form name="dateForm">
336-
<p><input name="dateField" value="Click Here for Datepicker" ng-model="date" ui-date></p>
337+
<p><input name="dateField" value="Click Here for Datepicker" ng-model="date" ui-date></p>
337338
</ng-form>
338339
<p>Selected Date: {{ date }}</p>
339340
<p>Formatted Date: {{ date | date: 'mediumDate'}}</p>
340341
<p>Selected Month: {{ date.getMonth() }}</p>
341342
<div ng-model="date" ui-date></div>
342-
</div>
343+
</div>
343344
</div>
344345
<div class="span6">
345346
<h3>Why?</h3>
@@ -400,7 +401,7 @@ <h3>Why?</h3>
400401
<h3>How?</h3>
401402
<pre class="prettyprint" ng-non-bindable>
402403
&lt;input ng-model="maskDemo" ui-mask="'99-99-9999'"&gt;
403-
404+
404405
</pre>
405406
</section>
406407

@@ -456,6 +457,53 @@ <h3>How?</h3>
456457
</div>
457458
</section>
458459

460+
<section id="directives-validate">
461+
<div class="page-header">
462+
<h1>Validate</h1>
463+
</div>
464+
<div class="row">
465+
<div class="span6">
466+
<h3>What?</h3>
467+
<p>The <code>ui-validate</code> directive makes it very easy to use any function as a validation function for input elements using ngModel.</p>
468+
<div class="well" ng-controller="ValidateCtrl">
469+
<form name="form">
470+
471+
<label>e-mail</label>
472+
<input name="email" type="email" required ng-model="email" ui-validate='{blacklist : notBlackListed}'>
473+
<span ng-show='form.email.$error.blacklist'>This e-mail is black-listed!</span>
474+
<br>is form valid: {{form.$valid}}
475+
<br>email errors: {{form.email.$error | json}}
476+
</form>
477+
</div>
478+
<h3>Why?</h3>
479+
<p>AngularJS comes with several built-in validation mechanism for input fields (ngRequired, ngPattern etc.) but using an arbitrary validation function requires creation of custom formatters and / or parsers. The ui-validate directive makes it easy to use any function(s) defined in scope as a validator function(s).</p>
480+
</div>
481+
<div class="span6">
482+
<h3>How?</h3>
483+
<p>Just add the 'ui-validate' directive to your input field.</p>
484+
<p>2 types of syntax are supported:
485+
<ul>
486+
<li><code>ui-validate="validateFoo"</code></li>
487+
<li><code>ui-validate="{foo : validateFoo, bar : validateBar}"</code></li>
488+
</ul>
489+
<pre class="prettyprint" ng-non-bindable>
490+
&lt;input ng-model="email" ui-validate='{blacklist : notBlackListed}'&gt;
491+
&lt;span ng-show='form.email.$error.blacklist'&gt;This e-mail is black-listed!&lt;/span&gt;
492+
</pre>
493+
and in a controller:
494+
<pre class="prettyprint" ng-non-bindable>
495+
function ValidateCtrl($scope) {
496+
$scope.blackList = ['bad@domain.com','verybad@domain.com'];
497+
$scope.notBlackListed = function(value) {
498+
return $scope.blackList.indexOf(value) === -1;
499+
};
500+
}
501+
</pre>
502+
</p>
503+
</div>
504+
</div>
505+
</section>
506+
459507
<section id="directives-reset" ng-controller="ResetCtrl">
460508
<div class="page-header">
461509
<h1>Reset</h1>

js/app.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ function KeypressCtrl($scope) {
6666
};
6767
}
6868

69+
function ValidateCtrl($scope) {
70+
71+
$scope.blackList = ['bad@domain.com','verybad@domain.com'];
72+
$scope.notBlackListed = function(value) {
73+
return $scope.blackList.indexOf(value) === -1;
74+
};
75+
}
76+
6977
function ScrollfixCtrl($scope) {
7078
$scope.scrollfix = -50;
7179
}

0 commit comments

Comments
 (0)