Skip to content

Commit

Permalink
fix(core/forms): notEmptyMessage reimplemented in retro-compatible way
Browse files Browse the repository at this point in the history
  • Loading branch information
robzan8 committed Jul 7, 2023
1 parent e1a94a7 commit c3b9f94
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface AjfValidationGroup {
maxValue?: AjfValidation;
minValue?: AjfValidation;
notEmpty?: AjfValidation;
notEmptyMessage?: string;
maxDigits?: AjfValidation;
minDigits?: AjfValidation;
conditions: AjfValidation[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,16 @@ export function evaluateValidationNotEmpty(
validation: AjfValidationGroup,
value: any,
): AjfValidationResult | null {
let ne = validation.notEmpty as AjfValidation | boolean | string | undefined;
const ne = validation.notEmpty as AjfValidation | boolean | undefined;
if (ne == null || ne === false) {
return null;
}
if (ne === true) {
ne = 'Value must not be empty';
}
if (typeof ne === 'string') {
return {
result: notEmpty(value),
error: ne,
error: validation.notEmptyMessage || 'Value must not be empty',
clientValidation: false,
};
}
return evaluateValidation(ne as AjfValidation, {'$value': value});
return evaluateValidation(ne, {'$value': value});
}
2 changes: 1 addition & 1 deletion projects/ionic/forms/src/forms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('AjfFormRenderer', () => {
label: 'foo',
nodeType: AjfNodeType.AjfField,
fieldType: AjfFieldType.String,
validation: {notEmpty: "The field's value must not be empty."},
validation: {notEmpty: true, notEmptyMessage: "The field's value must not be empty."},
} as any,
],
},
Expand Down

0 comments on commit c3b9f94

Please sign in to comment.