2

I have two DayPickerInput fields in a form and would like to mark them as required field but don't know how. Can anybody please help?

        <FormGroup row>
            <Col md="4">
                <Label htmlFor="begin">Begin</Label>
            </Col>
            <Col xs="12" md="8">
                <DayPickerInput value={this.state.begin}
                                format={settings.formatDate} />
            </Col>
        </FormGroup>
        <FormGroup row>
            <Col md="4">
                <Label htmlFor="end">End</Label>
            </Col>
            <Col xs="12" md="8">
                <DayPickerInput value={this.state.end}
                                format={settings.formatDate} />
            </Col>
        </FormGroup>

UPDATE: I tried with inputProps:

<DayPickerInput inputProps={required} />

but got error:

ReferenceError: required is not defined
LOUDKING
  • 301
  • 1
  • 13

2 Answers2

2

I tried with inputProps:

<DayPickerInput inputProps={required} /> 

but got error:

ReferenceError: required is not defined

This is how to pass object as prop:

<DayPickerInput 
   inputProps={
     { required: true }
   } 
/>
gpbl
  • 4,721
  • 5
  • 31
  • 45
0

You have to implement it at form-validation-level. Checkout Formik:

https://github.com/jaredpalmer/formik

Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43