Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
ReactJS agrega múltiples campos de entrada dinámicamente

Hola, soy nuevo en React y estoy perdido tratando de descubrir cómo agregar un campo de entrada dinámicamente con React. Si alguien puede ayudarme a descubrir cómo vincular un clic para agregar otro campo dinámicamente al formulario. ¿Cómo puedo hacer clic en el botón Agregar y aparecerá otra entrada de opción?

 class AddPost extends Component { static contextTypes = { router: React.PropTypes.object }; appendInput() { var newInput = `input-${this.state.inputs.length}`; this.setState({ inputs: this.state.inputs.concat([newInput]) }); } handleFormSubmit(formProps){ this.props.addPost(formProps); this.context.router.push('/posts'); } render(){ const {handleSubmit,fields:{title,option}} = this.props; return ( <div className="row top-buffer"> <div className="col md-auto"> <form onSubmit={handleSubmit(this.handleFormSubmit.bind(this))}> <fieldset className="form-group"> <label>Question:</label> <input {...title} className="form-control" placeholder="Enter question here"/> {title.touched && title.error && <div className="text-danger">{title.error}</div>} </fieldset> <fieldset className="form-group"> <label>Option:</label> <input {...option} className="form-control" placeholder="Enter option"/> {option.touched && option.error && <div className="text-danger">{option.error}</div>} </fieldset> <fieldset className="form-group"> <label>Option:</label> <input {...option} className="form-control" placeholder="Enter option"/> {option.touched && option.error && <div className="text-danger">{option.error}</div>} </fieldset> <button className="btn btn-success">Add</button> </form> <button onClick={ () => this.appendInput() }> CLICK ME TO ADD AN INPUT </button> </div> </div> ); } } function validate(formProps){ const errors = {}; if(! formProps.title){ errors.title = "Title is required"; } if(! formProps.option){ errors.body = "Option is required"; } return errors; } function mapStateToProps(state){ return { posts:state.post } } export default reduxForm({ form:'post', fields:['title','body'], validate:validate, },mapStateToProps,{addPost})(AddPost);
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si está utilizando redux-form . Consulte el ejemplo con FieldArray , eso debería ayudar.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!