iway1 / react-ts-form

https://react-ts-form.com
MIT License
2.01k stars 35 forks source link

How to add `id` prop to each of the form inputs #59

Closed nikitavoloboev closed 1 year ago

nikitavoloboev commented 1 year ago

Is your feature request related to a problem? Please describe.

We are testing our react app and that requires the input element to have a certain id prop like emailAddress or orderNumber.

I read docs and could not find a way to add them using this library as you seem to only be able to pass props or id to the wrapper div that wraps over the inputs and not each individual input itself. Unless I am mistaken.

Describe the solution you'd like

Be able to add id prop to each individual input box.

iway1 commented 1 year ago

you can pass any prop you want to the child component. Is this what you mean?

function TextField({id}:{id: string}){
  // ..
}

function Page() {
  return (
    <Form 
      props={{
        textField: {
          id: 'anId'
        }
      }}
    />
  )
}

props will pass to the input components and you can do whatever you want with the props. That work?

iway1 commented 1 year ago

Closing because of lack of activity, feel free to reopen if the above isn't solving your problem

nikitavoloboev commented 1 year ago

Yes thank you it did solve it.