blob: c5ea993620875ad14a48d632a3a9f9860aecaa15 [file] [log] [blame]
Matteo Scandolo4ba4cf12016-04-20 16:36:17 -07001/**
2 * © OpenCORD
3 *
4 * Visit http://guide.xosproject.org/devguide/addview/ for more information
5 *
6 * Created by teone on 4/15/16.
7 */
8
9(function () {
10 'use strict';
11
12 angular.module('xos.uiComponents')
13
14 /**
15 * @ngdoc directive
16 * @name xos.uiComponents.directive:xosValidation
17 * @restrict E
18 * @description The xos-validation directive
19 * @param {Object} errors The error object
20 * @element ANY
21 * @scope
Matteo Scandoloebf4fad2016-04-22 12:05:37 -070022 * @example
23 <example module="sampleValidation">
24 <file name="index.html">
25 <div ng-controller="SampleCtrl as vm">
26 <div class="row">
27 <div class="col-xs-12">
28 <label>Set an error type:</label>
29 </div>
30 <div class="col-xs-2">
31 <a class="btn" ng-click="vm.errors.email = true" ng-class="{'btn-default': !vm.errors.email, 'btn-success': vm.errors.email}">
32 Email
33 </a>
34 </div>
35 </div>
36 <xos-validation errors="vm.errors"></xos-validation>
37 </div>
38 </file>
39 <file name="script.js">
40 angular.module('sampleValidation', ['xos.uiComponents'])
41 .controller('SampleCtrl', function(){
42 this.errors = {
43 email: false
44 }
45 });
46 </file>
47 </example>
Matteo Scandolo4ba4cf12016-04-20 16:36:17 -070048 */
49
50 .directive('xosValidation', function(){
51 return {
52 restrict: 'E',
53 scope: {
54 errors: '='
55 },
56 template: `
57 <div>
Matteo Scandolo199ec002016-04-22 10:53:49 -070058 <!-- <pre>{{vm.errors.email | json}}</pre> -->
Matteo Scandoloebf4fad2016-04-22 12:05:37 -070059 <xos-alert config="vm.config" show="vm.errors.email !== undefined && vm.errors.email !== false">
Matteo Scandolo4ba4cf12016-04-20 16:36:17 -070060 This is not a valid email
61 </xos-alert>
Matteo Scandoloebf4fad2016-04-22 12:05:37 -070062 <xos-alert config="vm.config" show="vm.errors.minlength !== undefined && vm.errors.minlength !== false">
63 Too short
64 </xos-alert>
65 <xos-alert config="vm.config" show="vm.errors.maxlength !== undefined && vm.errors.maxlength !== false">
66 Too long
67 </xos-alert>
68 <xos-alert config="vm.config" show="vm.errors.custom !== undefined && vm.errors.custom !== false">
69 Field invalid
70 </xos-alert>
Matteo Scandolo4ba4cf12016-04-20 16:36:17 -070071 </div>
72 `,
73 transclude: true,
74 bindToController: true,
75 controllerAs: 'vm',
76 controller: function(){
77 this.config = {
78 type: 'danger'
79 }
80 }
81 }
82 })
83})();