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

强颜欢笑 提交于 2020-01-31 07:28:50

问题


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

i jsut cannot find any way on how to do that . any help?


回答1:


i ended using this :

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

after this code runs, the form will create the field if it does not exists




回答2:


I have faced the same issue. What I do is to declare a Field like this and set the height to 0. It is a little bit hacky but it works in my case.

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

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

Hope it helps.




回答3:


you don't need to dispatch any action just perform this change whenever you need a hidden field in redux form.

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




回答4:


Technically you don't need to create a type=hidden field because you can call the change function for the 'hidden' field you want to change if the field doesn't exist Redux-form will add it to your form state like an actual field

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

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

export default MyForm

Whether you've set up initial values or not you'll always be able to call the change function with your new hidden value and it'll work anyway

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


来源:https://stackoverflow.com/questions/44218104/how-to-set-hidden-fields-in-redux-form-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!