Ashh
Ashh

Reputation: 46461

How to give default value and placeholder to redux form select field?

I have array iterating options of redux form option... How I will give dafault value and place holder because it shows the first value of array which don't want... I want to show the placeholder instead

  <Field
    name="facilityId"
    component="select"
    className="form-control"
    placeholder="sdsfdsafjdsafijdsaoi"
  >
    {owners.map((data, i) => {
      return (
        <option value={data._id} key={i}>{data.profile.name}</option>
      )
    })}
  </Field>

Upvotes: 4

Views: 4094

Answers (2)

Stone
Stone

Reputation: 2668

Using Redux-form, multiple select fields, and loading the options asynchronously - I had issues w/ the chosen answer not working 100% of the time. This works in my case. Notice the value is "".

<ControlLabel>Patients</ControlLabel>
<Field
    name="facilityId"
    component="select"
    className="form-control"
    placeholder="sdsfdsafjdsafijdsaoi"
>
    <option value="" disabled>Choose patient</option>
    {owners.map((data, i) => {
        return (
            <option value={data._id} key={i}>{data.profile.name}</option>
        );
    })}
</Field>

Upvotes: 1

stiil
stiil

Reputation: 127

You can do the following

<ControlLabel>Patients</ControlLabel>
    <Field
        name="facilityId"
        component="select"
        className="form-control"
        placeholder="sdsfdsafjdsafijdsaoi"
    >
        <option value="-1" disabled>Choose patient</option>
        {owners.map((data, i) => {
            return (
                <option value={data._id} key={i}>{data.profile.name}</option>
            );
        })}
    </Field>
<FormControl.Feedback />

PS: Sorry if the formatting is off. I'm typing with my phone.

Upvotes: 4

Related Questions