我正在尝试创建一个redux表单(使用redux-form),可以动态创建自己的输入.我无法弄清楚如何让redux-form知道已经创建的新字段.是否有可能动态更改redux-form在表单组件本身中传递的字段?我在想这个错吗?这是我正在使用的.
class AddCustomer extends Component { render() { class Form extends Component { constructor(props, context) { super(props, context) this.state = { inputsToAdd: [] }; } handleAddInput() { let inputsToAdd = this.state.inputsToAdd.slice(); inputsToAdd.push(this.state.inputsToAdd.length); this.setState({ inputsToAdd }); } submitForm(data) { console.log(data) this.setState({inputsToAdd: []}); this.props.dispatch(initialize('addCustomer', {})) } render() { const { fields, handleSubmit } = this.props; return ({this.state.inputsToAdd.map((element, index) => { return ( ) })}) } } Form = connectReduxForm({ form: 'addCustomer', fields: ['companyName', 'adminEmail'] })(Form); return () } }Add Customer
roman.. 10
从Redux Form 6.*开始,您可以实现您尝试使用的功能
请参阅下面的示例(摘自Redux文档并略微简化)
import React from 'react'
import { Field, FieldArray, reduxForm } from 'redux-form'
import validate from './validate'
const renderMembers = ({ fields, meta: { touched, error } }) => (
-
{touched && error && {error}}
{fields.map((member, index) =>
-
)}
)
const FieldArraysForm = (props) => {
const { handleSubmit, submitting } = props
return (
)
}
export default reduxForm({
form: 'fieldArrays', // a unique identifier for this form
validate
})(FieldArraysForm)
有关更多信息,请查看文档 http://redux-form.com/6.1.1/examples/fieldArrays/
从Redux Form 6.*开始,您可以实现您尝试使用的功能
请参阅下面的示例(摘自Redux文档并略微简化)
import React from 'react'
import { Field, FieldArray, reduxForm } from 'redux-form'
import validate from './validate'
const renderMembers = ({ fields, meta: { touched, error } }) => (
-
{touched && error && {error}}
{fields.map((member, index) =>
-
)}
)
const FieldArraysForm = (props) => {
const { handleSubmit, submitting } = props
return (
)
}
export default reduxForm({
form: 'fieldArrays', // a unique identifier for this form
validate
})(FieldArraysForm)
有关更多信息,请查看文档 http://redux-form.com/6.1.1/examples/fieldArrays/