Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation error for type=date #2568

Open
ricardo118 opened this issue Jun 27, 2019 · 0 comments
Open

Validation error for type=date #2568

ricardo118 opened this issue Jun 27, 2019 · 0 comments

Comments

@ricardo118
Copy link
Contributor

input type=date works fine on all modern browsers that support that type. The problems arise in non supporting browsers:

Internet Explorer and Safari

The date picker on modern browsers allows the user to pick a date visually and then submits it using the ISO standard of yyyy-mm-dd.

However, on the fallback for IE/Safari there is no visual picker and its just a type=text field, which will fail validation unless the users submit yyyy-mm-dd which is relatively uncommon thing to ask for.

if we look in system/src/Grav/Common/Data/Validation.php Line 490

public static function typeDate($value, array $params, array $field)
{
    if (!isset($params['format'])) {
        $params['format'] = 'Y-m-d';
    }

    return self::typeDatetime($value, $params, $field);
}

we can see there is an optional format. So by modifying our form such as:

date:
  type: date
  label: Date
  validate:
    required: true
    format: 'm-d-Y'

This now passes validation for IE/Safari but will fail in modern browsers where the visual picker still submits yyyy-mm-dd

Potential fix

  • add an option for validate: such as date: false that will make sure the field is required but not validated against a date, letting us submit 2 different type of inputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants