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 2738274
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 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
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 2738274

Please sign in to comment.