mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #6482 from open-sausages/pulls/4.0/client-form-validation-warning
Client-side email validation rule
This commit is contained in:
commit
34903fd4a7
3
admin/client/dist/js/bundle.js
vendored
3
admin/client/dist/js/bundle.js
vendored
@ -424,7 +424,8 @@ case"alphanumeric":return u["default"].isAlphanumeric(e)
|
||||
case"alpha":return u["default"].isAlpha(e)
|
||||
case"regex":return u["default"].matches(e,n.pattern)
|
||||
case"max":return e.length<=n.length
|
||||
default:throw new Error("Unknown validation rule used: '"+t+"'")}}},{key:"validateFieldSchema",value:function l(e){return this.validateField(e.name,e.validation,null!==e.leftTitle?e.leftTitle:e.title,e.customValidationMessage)
|
||||
case"email":return u["default"].isEmail(e)
|
||||
default:console.warn("Unknown validation rule used: '"+t+"'")}}},{key:"validateFieldSchema",value:function l(e){return this.validateField(e.name,e.validation,null!==e.leftTitle?e.leftTitle:e.title,e.customValidationMessage)
|
||||
|
||||
}},{key:"getMessage",value:function d(e,t){var n=""
|
||||
if("string"==typeof t.message)n=t.message
|
||||
|
@ -56,8 +56,13 @@ class Validator {
|
||||
case 'max': {
|
||||
return value.length <= config.length;
|
||||
}
|
||||
case 'email': {
|
||||
return validator.isEmail(value);
|
||||
}
|
||||
default: {
|
||||
throw new Error(`Unknown validation rule used: '${rule}'`);
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`Unknown validation rule used: '${rule}'`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
/* global jest, describe, beforeEach, it, expect */
|
||||
/* global jest, describe, beforeEach, it, expect, console */
|
||||
|
||||
// Needs to be set before requiring other libraries
|
||||
global.console = { warn: jest.fn() };
|
||||
|
||||
jest.unmock('react');
|
||||
jest.unmock('react-addons-test-utils');
|
||||
@ -56,9 +59,9 @@ describe('Validator', () => {
|
||||
describe('validateValue()', () => {
|
||||
it('should throw an error', () => {
|
||||
validator = new Validator({});
|
||||
const callRuleDoesNotExist = () => validator.validateValue('one', 'ruledoesnotexist');
|
||||
|
||||
expect(callRuleDoesNotExist).toThrowError(/unknown/i);
|
||||
validator.validateValue('one', 'ruledoesnotexist');
|
||||
// eslint-disable-next-line no-console
|
||||
expect(console.warn).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user