Answer the question
In order to leave comments, you need to log in
How to implement dynamic select?
Hmm. The situation is crazy.
What is available - ReactJS, array with n-workers ala
{
id: 1,
name: 'вася'
},
{
id: 2,
name: 'petya'
}
Answer the question
In order to leave comments, you need to log in
With redux it will look like this:
erikras.github.io/redux-form/#/examples/deep?_k=3m09yp
UPD1. It will look something like this. But I would place the filter of the list of workers in select. Then you will need to get the form values from the store and do the same + you can use reselect to optimize this whole thing
UPD2. I have updated the code a bit. The old version didn't work...
class MyForm extends Component {
render() {
const { handleSubmit, fields: { workers }, workersList } = this.props
const selectedWorkersIds = workers.map(workerField => workerField.value.id)
const finalWorkersList = workersList.filter(
worker => selectedWorkersIds.indexOf(worker.id) === -1
)
return (
<form onSubmit={handleSubmit}>
<WorkersMultiInput
field={workers}
workersList={finalWorkersList}
/>
</form>
)
}
}
class WorkersMultiInput extends Component {
render() {
const { field, workersList } = this.props
return (
<div>
{
field.map((workerField, i) => {
// Просто добавим в список выбранного воркера
const finalWorkerList = [ workerField.value, ...workersList ]
return (
<WorkerInput key={i} field={workerField} workersList={finalWorkersList} />
)
}
}
</div>
)
}
}
can you use chosen or a similar plugin?
https://harvesthq.github.io/chosen/
It will be possible to select all workers in one input
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question