Custom ComponentsPremium
You can render custom components in the KendoReact Field component by using the built-in properties of the FieldRenderProps interface and any custom properties.
Using Basic Properties
You can get the Form state for the current field and trigger changes for it by using the value and onChange properties of the FieldRenderProps interface.
const MyCustomInput = (fieldRenderProps) => {
const {label, value, onChange} = fieldRenderProps;
return (
<Input label={label} value={value} onChange={onChange} />
);
};
const App = () => {
const handleSubmit = (dataItem) => alert(JSON.stringify(dataItem, null, 2));
return (
<Form
onSubmit={handleSubmit}
render={(formRenderProps) => (
<FormElement style={{maxWidth: 650}}>
<FieldWrapper>
<div className='k-form-field-wrap'>
<Field
name={'firstName'}
label={'First Name'}
component={MyCustomInput}
labelClassName={'k-form-label'}
/>
</div>
<FieldWrapper />
<div className="k-form-buttons">
<Button type={'submit'} disabled={!formRenderProps.allowSubmit}>
Submit
</Button>
</div>
</FormElement>
)}
/>
);
};
Setting Custom Behavior
You can display error messages and fully customize the behavior of the rendered component by using the additional properties of the Field component.
The Field passes every property that is not part of its own API, such as type or label, to the rendered component, together with the FieldRenderProps. When component is the name of an HTML element, such as "input", the additional properties become attributes of that element. When component is a custom component, the component receives them in its props and has to apply them. For example, spread the received type onto the Input to render an email input.
The following example demonstrates how to render a required custom checkbox a terms agreement.