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

Fix date of birthday validation issue #12004

Closed
selusi opened this issue Nov 3, 2017 · 6 comments
Closed

Fix date of birthday validation issue #12004

selusi opened this issue Nov 3, 2017 · 6 comments
Assignees
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@selusi
Copy link

selusi commented Nov 3, 2017

Preconditions

  1. PHP 7.0.22
  2. Apache2
  3. MySql5.6
  4. Magento 2.2.0

Steps to reproduce

  1. In backend Stores->Configuration->General->General->Locale options set locale as English (United States)
  2. In backend Stores->Configuration->Customer->Customer configuration->Name and address options set Show Date of Birth as optional or required
  3. In frontend open the page to create a new account and compile all fields and insert a date of birthday in format mm/dd/yyyy

Expected result

  1. Pass validation and create new account

Actual result

  1. Date of birthday doesn't pass validation because the format is wrong
  2. To pass validation You have to insert date in dd/mm/yyyy format

To fix the issue

The issue is a validation rule setted at line 212 of

vendor\magento\module-customer\Block\Widget\Dob.php

To fix the issue I have modified the method getHtmlExtraParams() to use the appropriate rule based on locale settings.
The original method

    public function getHtmlExtraParams()
    {
        $extraParams = [
            "'validate-date-au':true"
        ];

        if ($this->isRequired()) {
            $extraParams[] = 'required:true';
        }

        $extraParams = implode(', ', $extraParams);

        return 'data-validate="{' . $extraParams . '}"';
    }

New modified method

    public function getHtmlExtraParams()
    {
        /* NEW LINES */
        $firstDateLetter = substr(strtolower($this->getDateFormat()), 0, 1);
        if( $firstDateLetter == 'm'){
	    $rule = 'validate-date'; /* Rule for mm/dd/yyyy date format */
	} else{
	    $rule = 'validate-date-au'; /* Rule for dd/mm/yyyy date format */
	}
        /* END NEW LINES */
	$extraParams = [
            "'".$rule."':true" /* MODIFIED LINE */
        ];
      
        if ($this->isRequired()) {
            $extraParams[] = 'required:true';
        }

        $extraParams = implode(', ', $extraParams);

        return 'data-validate="{' . $extraParams . '}"';
    }
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Nov 3, 2017
@valentinboyanov
Copy link
Contributor

I am working on it at #mm17es

@valentinboyanov
Copy link
Contributor

The current issue was solved by the fixed issue #11067.

@magento-engcom-team
Copy link
Contributor

@selusi, thank you for your report.
We've created internal ticket(s) MAGETWO-83300 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.2.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed labels Nov 6, 2017
@okorshenko
Copy link
Contributor

Fixed in 2.2-develop

@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Dec 1, 2017
@SundarAkula
Copy link

SundarAkula commented Jan 14, 2020

Hi there, Can you please help with DOB validation. I want to restrict the customer based on 18 years.

@Paksifules95
Copy link

Hi there, Can you please help with DOB validation. I want to restrict the customer based on 18 years.

Hi SundarAkula, you have a solution to this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

7 participants