Skip to content

Commit

Permalink
refactor(core): update date form field
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-alexsaiannyi committed Aug 6, 2024
1 parent f867297 commit 9dd4cc9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const createRadioButtonsValidationHandler =
const createDatesValidationHandler =
(dateStateSetter: FieldStateSetFn<FieldState>, dateFieldState: FieldState) =>
(e: React.ChangeEvent<HTMLInputElement>) => {
const fieldId = Number(e.target.id.split('-')[1]);
const fieldId = Number(e.target.name.split('-')[2]);
const validationStatus = e.target.validity.valueMissing;

dateStateSetter({ ...dateFieldState, [fieldId]: !validationStatus });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,18 @@ export const DateField = ({
return (
<Field className="relative" name={name}>
<fieldset className="space-y-2">
<FieldLabel htmlFor={`field-${field.entityId}`} isRequired={field.isRequired}>
<FieldLabel htmlFor={name} isRequired={field.isRequired}>
{field.label}
</FieldLabel>
<DatePicker
disabledDays={disabledDays}
<input
id={`field-${field.entityId}`}
name={name}
type="hidden"
value={date ? new Date(date).toLocaleDateString() : ''}
/>
<DatePicker
disabledDays={disabledDays}
id={name}
onChange={field.isRequired ? onChange : undefined}
onInvalid={field.isRequired ? onChange : undefined}
onSelect={handleDateSelect}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export const RadioButtons = ({
const itemId = option.entityId;

return (
<div className="mb-2 flex" key={itemId}>
<RadioItem
id={`${itemId}`}
value={`${itemId}`}
variant={validationError ? 'error' : undefined}
/>
<Label className="w-full cursor-pointer ps-4 font-normal" htmlFor={`${itemId}`}>
<p className="inline-flex w-full justify-between">{option.label}</p>
<div className="mb-2" key={itemId}>
<Label className="flex w-full cursor-pointer gap-3 ps-4 font-normal">
<RadioItem
id={`${itemId}`}
value={`${itemId}`}
variant={validationError ? 'error' : undefined}
/>
<p>{option.label}</p>
</Label>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions core/components/ui/date-picker/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const DatePicker = React.forwardRef<React.ElementRef<'div'>, DatePickerPr
<Popover>
<PopoverTrigger asChild>
<Input
className={required ? 'caret-transparent' : ''}
placeholder={placeholder}
readOnly={!required}
required={required}
Expand Down

0 comments on commit 9dd4cc9

Please sign in to comment.