Added validation to form: required, minlength, maxlength
diff --git a/views/ngXosLib/xosHelpers/spec/ui/form.test.js b/views/ngXosLib/xosHelpers/spec/ui/form.test.js
index 32e91be..567f145 100644
--- a/views/ngXosLib/xosHelpers/spec/ui/form.test.js
+++ b/views/ngXosLib/xosHelpers/spec/ui/form.test.js
@@ -102,6 +102,7 @@
describe('the _getFieldFormat method', () => {
it('should return string', () => {
expect(service._getFieldFormat('string')).toEqual('string');
+ expect(service._getFieldFormat(null)).toEqual('string');
});
it('should return mail', () => {
expect(service._getFieldFormat('test@onlab.us')).toEqual('email');
@@ -166,6 +167,7 @@
scope.config = {
exclude: ['excludedField'],
+ formName: 'testForm',
actions: [
{
label: 'Save',
@@ -261,6 +263,42 @@
expect(isolatedScope.ngModel.enabled).toEqual(true);
});
});
+
+ describe('the custom validation options', () => {
+ beforeEach(() => {
+ scope.config.fields.first_name.validators = {
+ minlength: 10,
+ maxlength: 15,
+ required: true
+ };
+
+ scope.$digest();
+ });
+
+ it('should validate required', () => {
+ scope.model.first_name = null;
+ scope.$digest();
+
+ expect(isolatedScope.testForm.first_name.$valid).toBeFalsy();
+ expect(isolatedScope.testForm.first_name.$error.required).toBeTruthy();
+ });
+
+ it('should validate minlength', () => {
+ scope.model.first_name = 'short';
+ scope.$digest();
+
+ expect(isolatedScope.testForm.first_name.$valid).toBeFalsy();
+ expect(isolatedScope.testForm.first_name.$error.minlength).toBeTruthy();
+ });
+
+ it('should validate maxlength', () => {
+ scope.model.first_name = 'this is way too long!';
+ scope.$digest();
+
+ expect(isolatedScope.testForm.first_name.$valid).toBeFalsy();
+ expect(isolatedScope.testForm.first_name.$error.maxlength).toBeTruthy();
+ });
+ });
});
});
});
diff --git a/views/ngXosLib/xosHelpers/spec/ui/validation.test.js b/views/ngXosLib/xosHelpers/spec/ui/validation.test.js
index eb92a05..782f03f 100644
--- a/views/ngXosLib/xosHelpers/spec/ui/validation.test.js
+++ b/views/ngXosLib/xosHelpers/spec/ui/validation.test.js
@@ -32,6 +32,10 @@
let availableErrors = [
{
+ type: 'required',
+ message: 'Field required'
+ },
+ {
type: 'email',
message: 'This is not a valid email'
},