Field with ComboBox component cannot set default value

1 Answer 777 Views
ComboBox Form Grid
Nur
Top achievements
Rank 1
Nur asked on 08 Jul 2021, 04:39 PM

Hi There,

I am using the Field with Combobox component, and I set allowCustom=true. And, the Component cannot get the Init{Edit DataGrid ROW value} value.

Here is code

Thank you,
<Form onSubmit={props.onSubmit} initialValues={props.item}
         render={formRenderProps => <FormElement>
              <fieldset className={"k-form-fieldset"}>
                <div className="mb-6">
                <Field component={ComboBox} name="prod_name" data={prodNameList} required={true} textField="name" 
                dataItemKey="value"  value={selectedName}
                 onChange={onChangeSelectedName} allowCustom={true} label={"Prod Name"}/>
                </div>
              </fieldset>
              <div className="k-form-buttons">
                <button type={"submit"} className="k-button k-primary" disabled={!formRenderProps.allowSubmit}>
                  Update
                </button>
                <button type={"submit"} className="k-button" onClick={props.cancelEdit}>
                  Cancel
                </button>
              </div>
            </FormElement>} />

1 Answer, 1 is accepted

Sort by
-1
Stefan
Telerik team
answered on 09 Jul 2021, 12:27 PM

Hello, Nur,

Thank you for the code.

When using a component inside a Form, the Form is attaching the value and onChange props internally. If they are set, this may cause issues with the component.

I made an example with a Form that edits a Grid, has a Combobox with allowCustom and it is working as expected:

https://stackblitz.com/edit/react-nvw1dc-imaz2p?file=app%2FeditForm.jsx

If the issue still occurs, please share an example reproducing the issue and I will be happy to take a look.

Regards,
Stefan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Nur
Top achievements
Rank 1
commented on 09 Jul 2021, 12:39 PM

Hi Stefan,

I found that example, few days ago. It doesn't support custom value. So, I have to use ComboBox. and, the ComboBox data source is object list not an array.

Thank you,
Stefan
Telerik team
commented on 12 Jul 2021, 05:28 AM

Hello, Nur,

The example I have shared has the allowCustom option on, did you checked the example I have shared:

                <Field
                  name={"Category"}
                  component={ComboBox}
                  data={categories}
                  textField={"CategoryName"}
                  label={"Category"}
                  allowCustom={true}
As for the data, the approach with objects is very similar.

Please modify the provided example to represent the issue, and I will inspect it and update it.
Tags
ComboBox Form Grid
Asked by
Nur
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or