Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog user - only run regex validation when validator_type is set to regex #397

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/dialog-user/services/dialogData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,26 @@ describe('DialogDataService test', () => {
expect(validation.message).toEqual('Entered text should match the format: ^1234');
});
});

describe('when the validator rule is present but the type is not regex', () => {
let testField;

beforeEach(() => {
testField = {
'type': 'DialogFieldTextBox',
'default_value': '123',
'required': true,
'validator_type': 'f',
'validator_rule': '^1234'
}
});

it('passes validation', () => {
let validation = dialogData.validateField(testField);
expect(validation.isValid).toEqual(true);
expect(validation.message).toEqual('');
});
});
});
});

Expand Down
3 changes: 2 additions & 1 deletion src/dialog-user/services/dialogData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ export default class DialogDataService {
validation.message = __('This field is required');
}
}

// Run check if someone has specified a regex. Make sure if its required it is not blank
if (field.validator_rule && validation.isValid === true) {
if (field.validator_rule && field.validator_type === 'regex' && validation.isValid === true) {
if (angular.isDefined(fieldValue) && !_.isEmpty(fieldValue)) {
// This use case ensures that an optional field doesnt check a regex if field is blank
const regexPattern = field.validator_rule.replace(/\\A/i, '^').replace(/\\Z/i,'$');
Expand Down