Skip to content

Commit 5f5cf2f

Browse files
authored
Merge pull request #255 from rvsia/fixUrlMessage
fix(renderer): allow URL validator to pass custom messages
2 parents 6c4aacd + 5ea6546 commit 5f5cf2f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

packages/react-form-renderer/src/tests/validators/validators.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ describe('New validators', () => {
266266
expect(validatorMapper(validators.URL)({})('https://www.')).toBe(failMessage);
267267
});
268268

269+
it('should return custom message', () => {
270+
const customMessage = 'customMessage';
271+
272+
expect(validatorMapper(validators.URL)({ message: customMessage })('https://www.')).toBe(customMessage);
273+
});
274+
269275
it('should validate only URL with ftp protocol', () => {
270276
expect(validatorMapper(validators.URL)({ protocol: 'ftp' })('https://www.google.com/')).toBe(failMessage);
271277
expect(validatorMapper(validators.URL)({ protocol: 'ftp' })('ftp://www.google.com/')).toBeUndefined();

packages/react-form-renderer/src/validators/validator-mapper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ export default validatorType => ({
3535
numericality({ [includeThreshold ? '<=' : '<']: value, ...rest }),
3636
[validators.MIN_NUMBER_VALUE]: ({ value, includeThreshold = true, ...rest }) =>
3737
numericality({ [includeThreshold ? '>=' : '>']: value, ...rest }),
38-
[validators.URL]: options => pattern({ pattern: url(options), message: 'String is not URL.' }),
38+
[validators.URL]: ({ message, ...options }) => pattern({ pattern: url(options), message: message || 'String is not URL.' }),
3939
})[validatorType];

0 commit comments

Comments
 (0)