Matteo Scandolo | fb667b0 | 2016-04-20 16:36:17 -0700 | [diff] [blame] | 1 | /** |
| 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 Scandolo | b6bfee3 | 2016-04-22 12:05:37 -0700 | [diff] [blame^] | 22 | * @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 Scandolo | fb667b0 | 2016-04-20 16:36:17 -0700 | [diff] [blame] | 48 | */ |
| 49 | |
| 50 | .directive('xosValidation', function(){ |
| 51 | return { |
| 52 | restrict: 'E', |
| 53 | scope: { |
| 54 | errors: '=' |
| 55 | }, |
| 56 | template: ` |
| 57 | <div> |
Matteo Scandolo | d702aff | 2016-04-22 10:53:49 -0700 | [diff] [blame] | 58 | <!-- <pre>{{vm.errors.email | json}}</pre> --> |
Matteo Scandolo | b6bfee3 | 2016-04-22 12:05:37 -0700 | [diff] [blame^] | 59 | <xos-alert config="vm.config" show="vm.errors.email !== undefined && vm.errors.email !== false"> |
Matteo Scandolo | fb667b0 | 2016-04-20 16:36:17 -0700 | [diff] [blame] | 60 | This is not a valid email |
| 61 | </xos-alert> |
Matteo Scandolo | b6bfee3 | 2016-04-22 12:05:37 -0700 | [diff] [blame^] | 62 | <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 Scandolo | fb667b0 | 2016-04-20 16:36:17 -0700 | [diff] [blame] | 71 | </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 | })(); |