Skip to content

Commit

Permalink
merge master in
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Oct 16, 2024
2 parents 3a26993 + cabaa43 commit 8183e37
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/process/validation/__tests__/Validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ describe('Validator', function () {
errors = [...errors, ...scope.errors.map((error) => error.errorKeyOrMessage)];
}
}
expect(errors).to.have.length(6);
expect(errors).to.have.length(7);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const timeField: TimeComponent = {
label: 'Time',
input: true,
dataFormat: 'HH:mm:ss',
format: 'HH:mm',
};

describe('validateTime', function () {
Expand Down
7 changes: 2 additions & 5 deletions src/process/validation/rules/validateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@ export const shouldValidate = (context: ValidationContext) => {
};

export const validateTimeSync: RuleFnSync = (context: ValidationContext) => {
const { component, data, path, value, config } = context;
const { component, data, path, value } = context;
if (!shouldValidate(context)) {
return null;
}
try {
if (!value || isComponentDataEmpty(component, data, path)) return null;
// Server side evaluations of validity should use the "dataFormat" vs the "format" which is used on the client.
const format = config?.server
? (component as TimeComponent).dataFormat || 'HH:mm:ss'
: (component as TimeComponent).format || 'HH:mm';
const format = (component as TimeComponent).dataFormat || 'HH:mm:ss';
const isValid = dayjs(String(value), format, true).isValid();
return isValid ? null : new FieldError('time', context);
} catch (ignoreErr) {
Expand Down

0 comments on commit 8183e37

Please sign in to comment.