Skip to content

Commit

Permalink
🐛 - fix: added intl to form component
Browse files Browse the repository at this point in the history
  • Loading branch information
Xaohs committed Jun 27, 2024
1 parent 7ef7d12 commit c7c16b4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/form/form/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export type FormProps = Omit<
/** The submit form label. */
labelSubmit?: string;

/** The validation error label */
labelValidationErrorRequired?: string;

/**
* (Built-in serialization only), whether the convert results to type inferred from input type (e.g. checkbox value
* will be boolean).
Expand Down Expand Up @@ -98,6 +101,7 @@ export const Form: React.FC<FormProps> = ({
initialValues = {},
secondaryActions = [],
labelSubmit = "",
labelValidationErrorRequired = "",
nonFieldErrors,
onChange,
onSubmit,
Expand Down Expand Up @@ -129,6 +133,14 @@ export const Form: React.FC<FormProps> = ({
defaultMessage: "verzenden",
});

const _labelValidationErrorRequired = labelValidationErrorRequired
? labelValidationErrorRequired
: intl.formatMessage({
id: "mykn.components.Form.labelValidationErrorRequired",
description: 'mykn.components.Form: The "required" validation error',
defaultMessage: "Veld {name} is verplicht",
});

/**
* Revalidate on state change.
*/
Expand Down Expand Up @@ -205,11 +217,16 @@ export const Form: React.FC<FormProps> = ({
getValueFromFormData(fields, valuesState, field);

const error = getErrorFromErrors(fields, errorsState, field);
const message =
error === 'Veld "{name}" is verplicht'
? _labelValidationErrorRequired
: error;

return (
<FormControl
key={field.id || index}
direction={direction}
error={error}
error={message}
forceShowError={!validateOnChange}
value={value}
onChange={defaultOnChange}
Expand Down
5 changes: 5 additions & 0 deletions src/lib/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
"description": "mykn.components.Form: The submit form label",
"originalDefault": "verzenden"
},
"mykn.components.Form.labelValidationErrorRequired": {
"defaultMessage": "Veld {name} is verplicht",
"description": "mykn.components.Form: The \"required\" validation error",
"originalDefault": "Veld {name} is verplicht"
},
"mykn.components.Kanban.labelMoveObject": {
"defaultMessage": "change position of item",
"description": "mykn.components.Kanban: The kanban \"move object position\" (accessible) label",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/i18n/messages/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
"description": "mykn.components.Form: The submit form label",
"originalDefault": "verzenden"
},
"mykn.components.Form.labelValidationErrorRequired": {
"defaultMessage": "Veld {name} is verplicht",
"description": "mykn.components.Form: The \"required\" validation error",
"originalDefault": "Veld {name} is verplicht"
},
"mykn.components.Kanban.labelMoveObject": {
"defaultMessage": "wijzig positie van onderdeel",
"description": "mykn.components.Kanban: The kanban \"move object position\" (accessible) label",
Expand Down

0 comments on commit c7c16b4

Please sign in to comment.