Skip to content

Commit

Permalink
2.6.0 - improved calling custom required validator function when valu…
Browse files Browse the repository at this point in the history
…e is filled
  • Loading branch information
Tynik committed Jan 13, 2025
1 parent d5be04e commit 1353570
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,23 @@ export const requiredBuiltInFieldValidator: HoneyFormFieldBuiltInValidator = ({
return;
}

let isEmpty: boolean;
const isEmpty =
fieldValue === undefined ||
fieldValue === null ||
fieldValue === '' ||
(Array.isArray(fieldValue) && !fieldValue.length);

let isErred = isEmpty;

if (typeof fieldConfig.required === 'function') {
isEmpty = fieldConfig.required({
if (isEmpty && typeof fieldConfig.required === 'function') {
isErred = fieldConfig.required({
formContext,
formFields,
formValues,
});
} else {
isEmpty =
fieldValue === undefined ||
fieldValue === null ||
fieldValue === '' ||
(Array.isArray(fieldValue) && !fieldValue.length);
}

if (isEmpty) {
if (isErred) {
fieldErrors.push({
type: 'required',
message: fieldConfig.errorMessages?.required ?? 'The value is required',
Expand Down

0 comments on commit 1353570

Please sign in to comment.