diff --git a/sample/index.tsx b/sample/index.tsx index 6ac42bd..44ea899 100644 --- a/sample/index.tsx +++ b/sample/index.tsx @@ -106,6 +106,12 @@ type onlineDto = { body: string; }; +const selectOptions = [ + { label: 'USA', value: 'USA' }, + { label: 'Canada', value: 'Canada' }, + { label: 'Mexico', value: 'Mexico' }, +]; + const fields = [ { label: 'Name', @@ -120,11 +126,14 @@ const fields = [ label: 'Country', name: 'country', type: FormFieldTypes.VirtualSelect, - options: [ - { label: 'USA', value: 'USA' }, - { label: 'Canada', value: 'Canada' }, - { label: 'Mexico', value: 'Mexico' }, - ] + options: selectOptions + }, + { + label: 'Birth Country', + name: 'birthCountry', + type: FormFieldTypes.Select, + options: selectOptions, + notRequired: true, }, { label: 'Can Drive?', @@ -135,6 +144,8 @@ const fields = [ label: 'License Date', name: 'licenseDate', type: FormFieldTypes.Date, + value: '2021-01-01', + notRequired: true, }, ]; diff --git a/src/Form/index.tsx b/src/Form/index.tsx index 5b87297..c30fb37 100644 --- a/src/Form/index.tsx +++ b/src/Form/index.tsx @@ -55,7 +55,7 @@ export const Form = ({ initialData, onSave, onCancel, columns = 3 }: F control={control} render={({ field }) => ( ({ initialData, onSave, onCancel, columns = 3 }: F control={control} render={({ field }) => ( c.value.toString() === field.value, - )?.value - } + value={initialData[index].options + ?.find((c) => c.value.toString() === field.value) + ?.value?.toString()} onValueChange={(e) => onSelectChange(e, field.onChange, item.onChange) } @@ -98,11 +96,9 @@ export const Form = ({ initialData, onSave, onCancel, columns = 3 }: F render={({ field }) => (