Availity / availity-reactstrap-validation

Easy to use React validation components compatible for reactstrap.
https://availity.github.io/availity-reactstrap-validation/
MIT License
191 stars 70 forks source link

Display formatting error message in AvDateRangeField #199

Closed prakash-jayabal closed 4 years ago

prakash-jayabal commented 4 years ago

@TheSharpieOne Need to display date formatting error message in AvDateRangeField component. My component is looking like below as of now.

When user is using keyboard to key in date either in start or end date fields, need to show Date formatting error message when user keys in an invalid date. How could I achieve this?

              <AvDateRangeField
                name="dateRange"
                onChange={handleDateRange}
                start={{
                  name: 'date.start',
                  required: true,
                  value: dateRange.startDate,
                  min: moment().subtract(12, "months").format("MM/DD/YYYY"),
                  max: moment().format("MM/DD/YYYY"),
                  errorMessage: "Inquiries are accessible for up to 12 months in the past from current date."
                }}
                end={{
                  name: 'date.end',
                  required: true,
                  value: dateRange.endDate,
                  min: moment().subtract(12, "months").format("MM/DD/YYYY"),
                  max: moment().format("MM/DD/YYYY"),
                  errorMessage: "Inquiries are accessible for up to 12 months in the past from current date."
                }}
                required
                min={moment().subtract(12, "months").format("MM/DD/YYYY")}
                max={moment().format("MM/DD/YYYY")}
                validate={{
                  required: {
                    value: required,
                    errorMessage: "This field is required",
                  }
                }}
              />
TheSharpieOne commented 4 years ago

There isn't really a way. Invalid values are treated as null and triggers the required validation and that message appears. In fact, to sanitize the bad data, the invalid values gets converted to null for the validation. Because of that here isn't a way to different between no/empty value and a value that is not formatted correctly. The only thing you can do is combine the required verbiage with the invalid format verbiage. 😞

prakash-jayabal commented 4 years ago

ok Thanks @TheSharpieOne