redux-form

Redux form defaultValue

不问归期 提交于 2019-11-29 16:55:04
问题 How to set defaultValue to input component? <Field name={`${prize}.rank`} defaultValue={index} component={Input} type='text'/> I tried like above but my fields are empty. I'm trying to create fieldArray (dynamic forms): {fields.map((prize, index) => <div key={index} className="fieldArray-container relative border-bottom" style={{paddingTop: 35}}> <small className="fieldArray-title marginBottom20">Prize {index + 1} <button type="button" title="Remove prize" className="btn btn-link absolute

How to use React refs to focus a Redux Form field?

微笑、不失礼 提交于 2019-11-29 14:04:41
I am trying to use React refs to focus a Redux-Form Field when it mounts. When I try this.refs.title.getRenderedComponent().focus() in componentDidMount , an error is thrown saying: edit_fund.js:77 Uncaught TypeError: Cannot read property 'getRenderedComponent' of undefined When I console.log this.refs, it is mostly an empty object and sometimes identifies 'title' as being a ref, but it is not dependable. Am I using refs incorrectly? My code is below for reference. componentDidMount = () => { this.refs.title .getRenderedComponent() .focus(); } ... <Field id="title" name="title" component=

How do you pass in a dynamic form name in redux form?

[亡魂溺海] 提交于 2019-11-29 05:46:37
问题 Im trying to use this code to pass a dynamic form name into reduxForm. Here is the code that I found: let FormAddress = compose(connect((state, props) => ({form: props.form})), reduxForm({destroyOnUnmount: false, asyncBlurFields: []}))(ValidationForm); From this article: https://github.com/erikras/redux-form/issues/603#issuecomment-254271319 But I'm not really sure whats going on. This is how I'm currently doing it: const formName = 'shippingAddress'; const form = reduxForm({ form: formName }

DatePicker in Redux Form

谁说胖子不能爱 提交于 2019-11-29 04:28:19
i'd like to use DatePicker for selecting date using redux form. I create this: import React from 'react'; import DatePicker from 'react-datepicker'; import 'react-datepicker/dist/react-datepicker.css'; export default field => ( <div> <DatePicker onChange={field.value} selected={field.value} isClearable={true} > {field.children} </DatePicker> {field.meta.touched && field.meta.error && <span className="error">{field.meta.error}</span>} </div> ); <div className="form-group"> <div className="col-xs-12 col-sm-3 "> <div className="label" htmlFor="date-to">DATE TO</div>{' '} <Field id="date-to" name=

Typing redux forms v7 with TypeScript and React

浪子不回头ぞ 提交于 2019-11-29 03:15:19
问题 I've got a plain react-redux-powered form. I wish for there to be a form.container.tsx and a form.component.tsx, where form.container.tsx holds all the connections to redux state minus the Field's. I'm trying to wrap my container in react-redux's connect and then wrapping reduxForm within it to look something like TypeScript, redux-form and connect: (ideal) form.container.tsx: interface DummyFormContainerProps {} export const DummyFormContainer: React.SFC<DummyFormContainerProps> = props => {

Redux Form: How to handle multiple buttons?

爱⌒轻易说出口 提交于 2019-11-28 23:19:09
I am trying to add a second submit button to a redux-form . Both buttons should dispatch an action that saves the data but depending on the button pressed the user should be routed to different pages. So I defined a handler that I pass as onSubmit prop to the form. But as far as I can see only the form data is passed to this handler: The docs on handleSubmit note: A function meant to be passed to <form onSubmit={handleSubmit}> or to <button onClick={handleSubmit}> . It will run validation, both sync and async, and, if the form is valid, it will call this.props.onSubmit(data) with the contents

Make server validation using redux-form and Fetch API

与世无争的帅哥 提交于 2019-11-28 22:58:08
问题 How to make server-side validation using redux-form and Fetch API? There are "Submit Validation" demo provided in the docs which says that recommended way to do server side validation is to return a promise from the onSubmit function. But where should I place that promise? As I understood onSubmit function should be my action. <form onSubmit={this.props.addWidget}>... Where this.props.addWidget is actually my action, provided below. import fetch from 'isomorphic-fetch'; ... function

Redux-Form initial values from

若如初见. 提交于 2019-11-28 22:23:48
I'm trying to fill the profile form with data from API. Unfortunately redux-form doesn't want to cooperate with me in this case. For some reason fields stays empty whatever I do. Setting the fixed values instead of values passed from reducer work well for some reason. Maybe this is because I'm using redux-promise for API calls inside the action creators? How can I live with it and get rid of this. Here is my form component. import React, { Component } from 'react'; import { reduxForm, Field } from 'redux-form'; import { connect } from 'react-redux'; import { fetchRoleList, fetchUserData } from

Redux-form handleSubmit: How to access store state?

淺唱寂寞╮ 提交于 2019-11-28 20:17:46
In a redux-form handleSubmit function, which makes an Ajax call, some properties from the Redux state are needed in the Ajax (e.g. user ID). This would be easy enough if I wanted to define handleSubmit in the form's component: Just call mapStateToProps to pass in whatever I need, and read it from this.props in my handleSubmit . However, like a good React-Redux developer I write separate view components and containers , so my view components can be simple with little or no behavior. Therefore, I want to define handleSubmit in my container . Again, simple - redux-form is set up to do that.

How to use React refs to focus a Redux Form field?

可紊 提交于 2019-11-28 07:36:48
问题 I am trying to use React refs to focus a Redux-Form Field when it mounts. When I try this.refs.title.getRenderedComponent().focus() in componentDidMount , an error is thrown saying: edit_fund.js:77 Uncaught TypeError: Cannot read property 'getRenderedComponent' of undefined When I console.log this.refs, it is mostly an empty object and sometimes identifies 'title' as being a ref, but it is not dependable. Am I using refs incorrectly? My code is below for reference. componentDidMount = () => {