I am using redux-form for a user registration form.
For the Date of Birth section of the form, I have a <select>
field for day, month, and year.
So far, I have been using the Fields
component of redux-form
to capture each of the day, month, and year as separate variables:
const dobSelects = fields => {
const { label, input } = fields;
return (
<div>
<label>{label}</label>
<select {...fields.day.input} name="dob" id="">
<option />
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<select {...fields.month.input} id="">
<option />
<option value="january">January</option>
<option value="february">February</option>
<option value="march">March</option>
</select>
<select {...fields.year.input} id="">
<option />
<option value="2000">2000</option>
<option value="2001">2001</option>
<option value="2002">2002</option>
</select>
</div>
);
};
This yields the following into my values to be submitted:
{day: "2", month: "january", year: "2002"}
However, what if I want to send one field as a Date
object as opposed to three separate fields, while maintaining the same user interface?
I want the user to select the three fields, and instead of sending three separate fields, one dateOfBirth
field as a Date
object gets sent instead.
Furthermore, the Fields
component of redux-form does not seem sufficient in this case because I cannot pass it a validate
prop to validate the date of birth; I need to validate the three fields as one rather than separately.
How is this possible to achieve with redux-form?