How to set hidden fields in redux form in native reaction?

How to set hidden fields in redux form in native reaction?

i jsut cannot find a way to do this. any help?

+11
source share
4 answers

i finished using this:

this.props.dispatch(change("FORM_NAME","FIELD_NAME","VALUE")) 

after running this code, the form will create a field if it does not exist

+10
source

I ran into the same problem. What I do is declare the field like this and set the height to 0. This is a bit of hacks, but it works in my case.

<Field
    component={TextInput}
    name="departure_city_name"
    type="hidden"
    style={{ height: 0 }}
/>

And I change the value as follows: this.props.change("departure_city_name", cityData.name);

Hope this helps.

+5
source

- , , .

this.props.change('Field_name', value)

+2

Technically, you do not need to create a type = hidden field, because you can call a function changefor the β€œhidden” field that you want to change if the field does not exist. The redux form will add it to the form state, as the actual field

MyForm = reduxForm({
  form: 'myForm'
})(MyForm)

MyForm = connect(
  state => ({
    initialValues: { areYouOk: 'no' }
  })
)(MyForm)

export default MyForm

Whether you set the initial values ​​or not, you can always call the change function with a new hidden value, and it will still work

  let MyForm = ({ submitHandler, change }) => {
    return (
      <form onSubmit={submitHandler}>
        <button
         onClick={() => {
           change('areYouOk', 'yes');
         }}
         label={'Yes'}
        />
      </form>
    );
  }
+2
source

Source: https://habr.com/ru/post/1678037/


All Articles