We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how to use dropdown list component with react hook form (form library)

Hi,
I have tried many different ways connect dropdown list with react-hook-form implementation but value is not binding.could you please me with this,
Code:
import { DropDownListComponentDropDownListModel } from "@syncfusion/ej2-react-dropdowns";
import React from "react";
import { useControllerControl } from "react-hook-form";
import FormControllerWrapper from "./FormControllerWrapper";
interface CbDropdownListProps {
    controlControl<any>;
    namestring;
    defaultValue?: any;
    dropdownListProps?: DropDownListModel;
    heading?:string;
}
const CbDropdownListReact.FC<CbDropdownListProps> = ({ controldefaultValuenamedropdownListProps ,heading}) => {
    const {
        field: { ...inputProps },
        fieldState: { invaliderror },
        formState: { isSubmitted }
    } = useController({
        name,
        control,
        defaultValue,
    });
    const selectHandler=(props:any=> {
        console.log(props)
    }
    const changeHandler=(props:any=> {
        console.log(props)
    }
    return (
        <FormControllerWrapper heading={heading}>
     <DropDownListComponent   {...dropdownListProps}  
       {...inputProps}
      change={inputProps.onChange}
     floatLabelType='Never'/>
            {isSubmitted && invalid && error && (<div>{error?.message}</div>)}
    </FormControllerWrapper>
    );
}

export default CbDropdownList;







Form:
import { RowCol } from "react-bootstrap";
import { ButtonComponent } from "@syncfusion/ej2-react-buttons";
import * as yup from "yup";
import { SubmitHandler } from "react-hook-form";
import getYupSchema from "../../../Helpers/getYupSchema";
import useCbForm from "../../../Hooks/useCbForm";
import { CoachingSession } from "../../../Models/CoachingSessionModel";
import CbDatePicker from "../../UI/FormControllers/CbDatePicker";
import CbCheckbox from "../../UI/FormControllers/CbCheckbox";
import CbDropdownList from "../../UI/FormControllers/CbDropdownList";
import CbRichTextEditor from "../../UI/FormControllers/CbRichTextEditor";
import { COACHING_SESSION_TYPES } from "../../../Constants/GlobalConstants";
import CbTextBox from "../../UI/FormControllers/CbTextBox";


// creating yup Schema
const yupSchema = getYupSchema({
    email:yup.string(),
    date_utc: yup.date(),
    coaching_session_duration: yup.number(),
    cancelled_late: yup.boolean(),
    coaching_session_type: yup.string(),
    coaching_session_notes: yup.string(),
    what_to_work_on_next: yup.string(),
});
const ManageCoachingSessionForm = () => {
    const { controlhandleSubmitformState } = useCbForm({
        date_utc: null,
        coaching_session_duration: 0,
        cancelled_late: false,
        coaching_session_type: '',
        coaching_session_notes: '',
        what_to_work_on_next: ''
    }, yupSchema);
    const onSubmitSubmitHandler<CoachingSession> = data => {
        console.log(data)

    };
    console.log(formState.isValid)
    return (
        <div className='container mt-5'>
            <form onSubmit={handleSubmit(onSubmit)}>
                <Row>
                    <Col>
                        <CbDatePicker
                            name="date_utc"
                            heading='Session Date'
                            control={control}
                            datePickerProps={placeholder: 'Session Date' }}
                        />
                    </Col>
                    <Col>
                        <CbDropdownList
                            name="coaching_session_duration"
                            control={control}
                            heading='Session Duration'
                            dropdownListProps={{
                                placeholder: 'Session Duration',
                                dataSource: [306090120],
                                showClearButton: true
                            }}
                        />
                    </Col>
                    <Col>
                        <CbCheckbox
                            name="cancelled_late"
                            control={control}
                            heading='Cancelled Late'
                            checkboxProps={label: 'Cancelled' }}
                        />
                    </Col>
                </Row>
                <br />
                <Row>
                    <Col>
                        <CbDropdownList
                            name="coaching_session_type"
                            control={control}
                            heading='Coaching Session Type'
                            dropdownListProps={{
                                placeholder: 'Coaching Session Type',
                                dataSource: COACHING_SESSION_TYPES,
                                width: "50%",
                                showClearButton: true
                            }} />
                    </Col>
                    <Col>
                    <CbTextBox
                  name="email"
                  control={control}
                  heading="Email"
                  textBoxProps={placeholder: 'Enter your email' }}
                />
                    </Col>
                </Row>
                <br />
                <Row>
                    <Col>
                        <CbRichTextEditor
                            name="coaching_session_notes"
                            control={control}
                            heading='Session Notes'
                            richTextEditorProps={placeholder: 'Session Notes...'width: "70%" }}
                        />
                    </Col>
                </Row>
                <br />
                <Row>
                    <Col>
                        <CbRichTextEditor
                            name="what_to_work_on_next"
                            control={control}
                            heading='What to Work on Next'
                            richTextEditorProps={{
                                placeholder: 'What to Work on Next...',
                                width: "70%"
                            }}
                        />
                    </Col>
                </Row>
                <br />
                <div className='d-flex justify-content-end'>
                    <ButtonComponent className="me-4">Cancel</ButtonComponent>
                    <ButtonComponent cssClass='e-primary' type="submit">Save Coaching Session</ButtonComponent>
                </div>
            </form>

        </div>
    )

}
export default ManageCoachingSessionForm;

19 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team May 21, 2021 02:57 AM UTC

Hi Darek, 

Thanks for contacting Syncfusion support. 

According to the information you have provided, the value in the Dropdownlist component is not bound. But, you didn't bind any value property to the component. Whether you are reporting that dropdownListProps (placeholder, datasource, showClearButton) are not bound to the component. Can you please elaborate on your reported query and, if possible, share a simple issue replicating sample, so that we can check and provide you with a solution as soon as possible. 

Regards, 
Ponmani M 



DJ Darek Johnson May 21, 2021 03:52 AM UTC

Hi,
i am including a test project with code sandbox which is available in below link
https://codesandbox.io/s/react-hook-form-with-ui-library-ts-forked-9yd17?file=/src/index.tsx:400-433

Here i have used another third party library react-select ,that worked fine which is a example given in react-hook-form libray itself
https://react-hook-form.com/get-started#IntegratingwithUIlibraries

In the same way i have included dropdown list of sync fusion ,the selected value is not able to bind with variable if we submit the above as you will see as alert

i have this road block to implement forms further with sync fusion components, where i can't move forward.

Could you please ,help me asap to get rid of this problem
Let me know still any information needed
Thank for your patience.


DJ Darek Johnson May 24, 2021 06:46 AM UTC

Hi,
could you please  give me solution ASAP to get rid of this problem as it blocks me on project


PM Ponmani Murugaiyan Syncfusion Team May 24, 2021 03:54 PM UTC

Hi Darek, 

Sorry for the delay. 

We able to replicate the reported issue in our end. We are currently validating and update further details in 2 business days (May 26, 2021). We appreciate your patience until then. 

Regards, 
Ponmani M 



DJ Darek Johnson May 24, 2021 05:46 PM UTC

Thank you so much for response. I am waiting for your solution.


PM Ponmani Murugaiyan Syncfusion Team May 26, 2021 04:09 PM UTC

Hi Darek, 

Sorry for the inconvenience caused. 

We are facing complexity in our end. We need additional time to validate further and update you in 2 business days (May 28, 2021). We appreciate your patience until then. 

Regards, 
Ponmani M 
1


DJ Darek Johnson May 31, 2021 01:48 PM UTC

Hi,

As it is blocking me to move forward, could you please provide me solution ASAP.

Thank you.


PM Ponmani Murugaiyan Syncfusion Team June 2, 2021 02:58 AM UTC

Hi Darek, 

We deeply regret for the inconvenience caused. 

Currently we are investigating further with this query. We will provide high priority and update in 1 business days (June 03, 2021). We appreciate your patience until then. 

Regards, 
Ponmani M 



PM Ponmani Murugaiyan Syncfusion Team June 4, 2021 03:07 AM UTC

Hi Darek, 
 
Sorry for the delay. 
 
We suggest you to add the name attribute to Dropdownlist component using the htmlAttributes properties, which adds the attributes to the root element. Please find the modified sample to get the selected value from dropdownlist. Kindly check and please get back us if you need further assistance. 
 
 
 
const htmlAttr = { name: "sports" }; 
 
<Controller 
render={({ field }) => ( 
    <DropDownListComponent {...field} dataSource={sportsData} placeholder="Select a game" htmlAttributes={htmlAttr}/> 
)} 
 
Regards, 
Ponmani M 



DC Daimler Clavel June 4, 2021 03:44 AM UTC

Hello! We appreciate the discussion since we are facing the same problem here integrating DropdownListComponent & MultiSelectComponent with react-hook-form. We tried your proposed solution but it didn't work. I tested the code you sent on Code Sandbox but seems like the value Golf for the Sport Name is not registered when I tried to submit the form as you can see in the console below.



DJ Darek Johnson June 4, 2021 12:05 PM UTC

Hi,

Still i am not able to bind the value from code sandbox in your example, could you please check again?


PM Ponmani Murugaiyan Syncfusion Team June 7, 2021 04:43 PM UTC

Hi Darek, 

Thanks for the update. 

Currently we are checking the reporting query with your provided information. We will update further details in 2 business days (June 09, 2021). We appreciate your patience until then. 

Regards, 
Ponmani M 



DJ Darek Johnson June 10, 2021 02:40 AM UTC

Hi,
Sorry for posting again, I appreciate your work on this problem.
But still I am looking for solution, This is blocking me to move forward, Please provide me at least work around.All other form controls also not working like checkbox,date picker, only textbox is working.


PM Ponmani Murugaiyan Syncfusion Team June 14, 2021 02:44 AM UTC

Hi Darek, 

Thanks for the update. 

We have prepared sample working with all form controls like TextBox, Numeric TextBox, Masked TextBox, DatePicker, DateTimePickr and CheckBox. Please find the sample below for reference. 

<form onSubmit={handleSubmit(onSubmit)}> 
<label>Textbox</label> 
<Controller 
  render={({ field }) => <TextBoxComponent {...field} />} 
  name="text" 
  control={control} 
  defaultValue="" 
/> 
<label>Numeric Textbox</label> 
<Controller 
  render={({ field }) => <NumericTextBoxComponent {...field} />} 
  name="numeric" 
  control={control} 
  defaultValue="" 
/> 
<label>Maksed Textbox</label> 
<Controller 
  render={({ field }) => <MaskedTextBoxComponent {...field} />} 
  name="mask" 
  control={control} 
  defaultValue="" 
/> 
<label>DatePicker</label> 
<Controller 
  render={({ field }) => <DatePickerComponent {...field} />} 
  name="date" 
  control={control} 
  defaultValue="" 
/> 
<label>DateTimePicker</label> 
<Controller 
  render={({ field }) => <TimePickerComponent {...field} />} 
  name="time" 
  control={control} 
  defaultValue="" 
/> 
<label>Checkbox</label> 
<Controller 
  render={({ field }) => ( 
    <CheckBoxComponent 
      checked={field.value} 
      change={(e: CheckboxArgs) => field.onChange(e.checked)} 
      {...field} 
    /> 
  )} 
  name="check" 
  control={control} 
/> 
<input type="submit" /> 
</form> 


 


Regards, 
Ponmani M 


Marked as answer

VI Vishal August 10, 2021 07:38 PM UTC

Hi Team,

I'm facing the same issue and not able to get a workaround while as per this thread the final solution provided did not have a dropdownlistcomponent example.

Can you please help out with a  dropdownlistcomponent  sample



DR Deepak Ramakrishnan Syncfusion Team August 11, 2021 04:30 PM UTC

Hi Vishal, 

Greetings from Syncfusion support. 

We have validated your requirement in our end . We will update the further details on or before 13th,August 2021. 

Thanks, 
Deepak R. 



DR Deepak Ramakrishnan Syncfusion Team August 13, 2021 06:03 PM UTC

Hi Vishal,  
 
Thanks for your patience . 
 
We can able to reproduce the issue at our end .We need to further validate the issue and update the possibilities on or before 17th, August 2021. We appreciate your patience until then. 
 
Thanks,  
Deepak R. 



SP Sureshkumar P Syncfusion Team August 18, 2021 08:49 AM UTC

Hi Vishal,   
  
Thanks for your patience.  
  
We have considered the issue ‘Selected value does not able to get dropdown list component with react hook form’ as bug in our end. And we will include the fix on upcoming weekly patch release scheduled on August 31st, 2021. You can track the status using the below feedback link.   
 
 
 
We appreciate your patience until then.   
  
Thanks,   
Sureshkumar P 



DR Deepak Ramakrishnan Syncfusion Team September 1, 2021 01:20 PM UTC

Hi Vishal, 
 
Thanks for your patience. 
 
We are glad to announce that our weekly release v19.2.0.57 is rolled out, which include the fix for the reported issue Selected value does not able to get dropdown list component with react hook form (form library) . So kindly upgrade to mentioned version or the latest to avail the fix. 
 
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance. 
 
Thanks, 
Deepak R. 


Loader.
Live Chat Icon For mobile
Up arrow icon