-
I am trying to do a multi select using React Native Dropdown Picker using React Hook Form Controller. I could get the multi select values in MultiSelect Form component but on submit I don't get the values in "handleSubmit" data. My code is below. Any help is much appreciated. Thank you! ` import RHFFormMultiSelect from '../../components/RHFFormMultiSelect'; const EditProfileOne = () => { const {control, handleSubmit} = useForm({ const navigation = useNavigation(); const handleNextPress = data => { <ScrollView showsVerticalScrollIndicator={false} style={{flex: 1, backgroundColor: colors.bgColor}}> <RHFFormSelect name="gender" placeholder="Gender" dropdownList={genderList} searchable={false} control={control} rules={{ required: 'Gender is required', }} /> <RHFFormMultiSelect name="language" placeholder="Languages Spoken" dropdownList={languageList} dropDownDirection="TOP" control={control} rules={{ required: 'Languages spoken is required', }} /> <AppButton title="Next" onPress={handleSubmit(handleNextPress)} style={{zIndex: -1}} /> </> ); }; Below is my MultiSelect Component: import {View, StyleSheet} from 'react-native'; import {Controller} from 'react-hook-form'; import DropDownPicker from 'react-native-dropdown-picker'; import {useState} from 'react'; import colors from '../config/colors'; const RHFFormMultiSelect = ({ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The <DropDownPicker
value={field.value}
setValue={cb => {
const newValue = cb(field.value)
field.onChange(newValue)
}}
/> Here's a working example codesandbox. |
Beta Was this translation helpful? Give feedback.
The
DropDownPicker
setValue
state callback doesn't return a new field value, but rather auseState's
setValue`-like callback that takes the current field value as an argument to resolve the new field value.Here's a working example codesandbox.