Skip to content

Commit

Permalink
Merge pull request #1361 from Chia-Network/fix-date-picker
Browse files Browse the repository at this point in the history
fix: address breaking changes in flowbite datepicker
  • Loading branch information
TheLastCicada authored Dec 5, 2024
2 parents 4da3425 + 5e52e89 commit 9d0b0bc
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/renderer/components/form/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,31 +139,33 @@ const Field: React.FC<FieldProps> = ({
options={options}
/>
);
case 'date':
// eslint-disable-next-line
case 'date': {
const props: any = {
showTodayButton: true,
showClearButton: false,
onSelectedDateChanged: (date) => {
onChange: (date) => {
const dateValue = date ? date.toISOString() : undefined;
console.log(`setting ${name} to ${dateValue}`);
setFieldValue(name, dateValue);
},
placeholder: 'Select date',
};

if (initialValue) {
props.defaultDate = new Date(initialValue);
}
const formValue = get(values, name);
const formValueIsDate = !isNaN(Date.parse(formValue));

if (!initialValue && !get(values, name)) {
if (!initialValue && !formValue) {
props.value = undefined;
} else if (formValue && formValueIsDate) {
props.value = new Date(formValue);
}

return (
<div key={initialValue}>
<Datepicker {...props} />
</div>
);
}
case 'checkbox':
return <Checkbox id={name} name={name} onChange={(e) => setFieldValue(name, e.target.checked)} />;
// Add cases for other field types as needed
Expand Down

0 comments on commit 9d0b0bc

Please sign in to comment.