Merged xosValidation pull-request
diff --git a/views/ngXosLib/xosHelpers/spec/services/helpers/form.helpers.test.js b/views/ngXosLib/xosHelpers/spec/services/helpers/form.helpers.test.js
index 404f63a..f6bfbb2 100644
--- a/views/ngXosLib/xosHelpers/spec/services/helpers/form.helpers.test.js
+++ b/views/ngXosLib/xosHelpers/spec/services/helpers/form.helpers.test.js
@@ -43,7 +43,8 @@
custom: {
label: 'Custom Label',
type: 'number',
- validators: {}
+ validators: {},
+ hint: 'Test Hint'
}
};
@@ -51,32 +52,38 @@
id: {
label: 'Id:',
type: 'number',
- validators: {}
+ validators: {},
+ hint: ''
},
name: {
label: 'Name:',
type: 'text',
- validators: {}
+ validators: {},
+ hint: ''
},
mail: {
label: 'Mail:',
type: 'email',
- validators: {}
+ validators: {},
+ hint: ''
},
active: {
label: 'Active:',
type: 'boolean',
- validators: {}
+ validators: {},
+ hint: ''
},
created: {
label: 'Created:',
type: 'date',
- validators: {}
+ validators: {},
+ hint: ''
},
custom: {
label: 'Custom Label:',
type: 'number',
- validators: {}
+ validators: {},
+ hint: 'Test Hint'
}
};
@@ -176,7 +183,8 @@
},
custom: {
label: 'Custom Label',
- type: 'number'
+ type: 'number',
+ hint: 'Test Hint'
}
};
@@ -184,32 +192,38 @@
id: {
label: 'Id:',
type: 'number',
- validators: {}
+ validators: {},
+ hint: ''
},
name: {
label: 'Name:',
type: 'text',
- validators: {}
+ validators: {},
+ hint: ''
},
mail: {
label: 'Mail:',
type: 'email',
- validators: {}
+ validators: {},
+ hint: ''
},
active: {
label: 'Active:',
type: 'boolean',
- validators: {}
+ validators: {},
+ hint: ''
},
created: {
label: 'Created:',
type: 'date',
- validators: {}
+ validators: {},
+ hint: ''
},
custom: {
label: 'Custom Label:',
type: 'number',
- validators: {}
+ validators: {},
+ hint: 'Test Hint'
}
};
diff --git a/views/ngXosLib/xosHelpers/spec/ui/validation.test.js b/views/ngXosLib/xosHelpers/spec/ui/validation.test.js
index 782f03f..bb663fa 100644
--- a/views/ngXosLib/xosHelpers/spec/ui/validation.test.js
+++ b/views/ngXosLib/xosHelpers/spec/ui/validation.test.js
@@ -7,27 +7,46 @@
(function () {
'use strict';
+ let compile, element, scope, isolatedScope;
+
+ const compileElement = (el) => {
+ element = el;
+
+ if(!scope){
+ scope = rootScope.$new();
+ }
+ if(!angular.isDefined(element)){
+ element = angular.element('<xos-validation field="field" form="form"></xos-validation>');
+ }
+ compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }
+
describe('The xos.helper module', function(){
describe('The xos-validation component', () => {
- let element, scope, isolatedScope;
-
beforeEach(module('xos.helpers'));
- beforeEach(inject(($compile, $rootScope) => {
+ describe('when the form has no errors', () => {
+ beforeEach(inject(($compile, $rootScope) => {
+ compile = $compile;
+ scope = $rootScope.$new();
- scope = $rootScope.$new();
+ scope.field = {
+ $error: {}
+ };
- scope.errors = {};
+ scope.form = {
+ $submitted: true
+ }
- element = angular.element(`<xos-validation errors="errors"></xos-validation>`);
- $compile(element)(scope);
- scope.$digest();
- isolatedScope = element.isolateScope().vm;
- }));
+ compileElement();
+ }));
- it('should not show an alert', () => {
- expect($(element).find('xos-alert > .alert')[0]).toHaveClass('ng-hide');
+ it('should not show an alert by default', () => {
+ expect($(element).find('xos-alert > .alert')[0]).toHaveClass('ng-hide');
+ });
});
let availableErrors = [
@@ -56,8 +75,8 @@
// use a loop to generate similar test
availableErrors.forEach((e, i) => {
it(`should show an alert for ${e.type} errors`, () => {
- scope.errors[e.type] = true;
- scope.$digest();
+ scope.field.$error[e.type] = true;
+ compileElement();
let alert = $(element).find('xos-alert > .alert')[i];
expect(alert).not.toHaveClass('ng-hide');
expect(alert).toHaveText(e.message);
diff --git a/views/ngXosLib/xosHelpers/src/services/helpers/ui/form.helpers.js b/views/ngXosLib/xosHelpers/src/services/helpers/ui/form.helpers.js
index c850f48..04a383a 100644
--- a/views/ngXosLib/xosHelpers/src/services/helpers/ui/form.helpers.js
+++ b/views/ngXosLib/xosHelpers/src/services/helpers/ui/form.helpers.js
@@ -21,6 +21,7 @@
* @returns {boolean} If the string match an email format
**/
+
this._isEmail = (text) => {
var re = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/;
return re.test(text);
@@ -81,7 +82,8 @@
* 'field-name': {
* label: 'Label',
* type: 'number', //typeof field
- * validators: {} // see xosForm for more details
+ * validators: {}, // see xosForm for more details
+ * hint: 'A Custom hint for the field'
* }
* }
* ```
@@ -97,7 +99,8 @@
form[f] = {
label: (customField[f] && customField[f].label) ? `${customField[f].label}:` : LabelFormatter.format(f),
type: (customField[f] && customField[f].type) ? customField[f].type : this._getFieldFormat(model[f]),
- validators: (customField[f] && customField[f].validators) ? customField[f].validators : {}
+ validators: (customField[f] && customField[f].validators) ? customField[f].validators : {},
+ hint: (customField[f] && customField[f].hint)? customField[f].hint : ''
};
if(form[f].type === 'date'){
diff --git a/views/ngXosLib/xosHelpers/src/services/rest/Slices_plus.js b/views/ngXosLib/xosHelpers/src/services/rest/Slices_plus.js
index e744caa..8213b11 100644
--- a/views/ngXosLib/xosHelpers/src/services/rest/Slices_plus.js
+++ b/views/ngXosLib/xosHelpers/src/services/rest/Slices_plus.js
@@ -22,5 +22,19 @@
return {$promise: deferred.promise};
}
+
+ this.get = (id, params) => {
+ let deferred = $q.defer();
+
+ $http.get(`/api/utility/slicesplus/${id}`, {params: params})
+ .then(res => {
+ deferred.resolve(res.data);
+ })
+ .catch(res => {
+ deferred.reject(res.data);
+ });
+ return {$promise: deferred.promise};
+
+ }
})
})();
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.component.js b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.component.js
index db4a2fd..92843c2 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/form/form.component.js
@@ -9,6 +9,7 @@
(function () {
'use strict';
+
angular.module('xos.uiComponents')
/**
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/validation/validation.component.js b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/validation/validation.component.js
index 84eb91a..dbe4fbb 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/validation/validation.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/dumbComponents/validation/validation.component.js
@@ -74,24 +74,24 @@
return {
restrict: 'E',
scope: {
- errors: '='
+ field: '=',
+ form: '='
},
template: `
<div ng-cloak>
- <!-- <pre>{{vm.errors.email | json}}</pre> -->
- <xos-alert config="vm.config" show="vm.errors.required !== undefined && vm.errors.required !== false">
+ <xos-alert config="vm.config" show="vm.field.$error.required !== undefined && vm.field.$error.required !== false && (vm.field.$touched || vm.form.$submitted)">
Field required
</xos-alert>
- <xos-alert config="vm.config" show="vm.errors.email !== undefined && vm.errors.email !== false">
+ <xos-alert config="vm.config" show="vm.field.$error.email !== undefined && vm.field.$error.email !== false && (vm.field.$touched || vm.form.$submitted)">
This is not a valid email
</xos-alert>
- <xos-alert config="vm.config" show="vm.errors.minlength !== undefined && vm.errors.minlength !== false">
+ <xos-alert config="vm.config" show="vm.field.$error.minlength !== undefined && vm.field.$error.minlength !== false && (vm.field.$touched || vm.form.$submitted)">
Too short
</xos-alert>
- <xos-alert config="vm.config" show="vm.errors.maxlength !== undefined && vm.errors.maxlength !== false">
+ <xos-alert config="vm.config" show="vm.field.$error.maxlength !== undefined && vm.field.$error.maxlength !== false && (vm.field.$touched || vm.form.$submitted)">
Too long
</xos-alert>
- <xos-alert config="vm.config" show="vm.errors.custom !== undefined && vm.errors.custom !== false">
+ <xos-alert config="vm.config" show="vm.field.$error.custom !== undefined && vm.field.$error.custom !== false && (vm.field.$touched || vm.form.$submitted)">
Field invalid
</xos-alert>
</div>