data-driven-forms / react-forms

React library for rendering forms.
https://data-driven-forms.org/
Apache License 2.0
295 stars 85 forks source link

Unable to make all the form fields touched programmatically. #1468

Closed adityapatil9191 closed 3 months ago

adityapatil9191 commented 3 months ago

Hello ,

I want to make all the form fields touched, once user moves from one accordion to another, in the given example . https://codesandbox.io/p/sandbox/react-data-driven-autocomplete-forked-9tkfvt?file=%2Fsrc%2FForm.jsx%3A17%2C26. The below code does not work . Can anyone please help me if I am doing anything wrong here?

const formOptions = useFormApi(); const {lastOpened, setFormState} = useAppContext(); const {fields} = useFieldsApi(props); //This if condition is to extract all the fields which were last opened and it is working as expected. if (fields && fields.length) { const filteredFieldItems = fields.filter((field:any)=> field.name === lastOpened) } if(filteredFieldItems && filtteredFieldItems.length) { filteredFieldItems[0].fields.forEach((field:any)=> { formOptions.focus(field.name); }) } The line highlighted above does not focus the fields. Is that a correct syntax? I am able to extract the fields .