0

So in my Customer edit form, I need to remove year , so on inspecting i found out the script code renders from

vendor/magento/framework/View/Element/Html/Date.php

code

$html .= '<script type="text/javascript">
        require(["jquery", "mage/calendar"], function($){
                $("#' .
        $this->getId() .
        '").calendar({
                    showsTime: ' .
        ($this->getTimeFormat() ? 'true' : 'false') .
        ',
                    ' .
        ($this->getTimeFormat() ? 'timeFormat: "' .
        $this->getTimeFormat() .
        '",' : '') .
        '
                    dateFormat: "' .
        $this->getDateFormat() .
        '",
                    buttonImage: "' .
        $this->getImage() .
        '",
                    ' .
        ($calendarYearsRange ? 'yearRange: "' .
        $calendarYearsRange .
        '",' : '') .
        '
                    buttonText: "' .
        (string)new \Magento\Framework\Phrase(
            'Select Date'
        ) .
        '"' . ($maxDate ? ', maxDate: "' . $maxDate . '"' : '') .
        ($changeMonth === null ? '' : ', changeMonth: ' . $changeMonth) .
        ($changeYear === null ? '' : ', changeYear: ' . $changeYear) .
        ($showOn ? ', showOn: "' . $showOn . '"' : '') .
        ($firstDay ? ', firstDay: ' . $firstDay : '') .
        '})
        });
        </script>';

and the generated html is

  require(["jquery", "mage/calendar"], function($){
                $("#dob").calendar({
                    showsTime: false,
                    dateFormat: "M/d/Y",
                    buttonImage: "https://x-bitbucket-pr-463-24lbvlq-aup5t2xnmlbog.us-3.magentosite.cloud/static/version1557136878/frontend/Mgs/yx_theme/en_US/Magento_Theme/calendar.png",
                    yearRange: "-120y:c+nn",
                    buttonText: "Select Date", maxDate: "-1d", changeMonth: true, changeYear: true, showOn: "both"})
        });

So how can I change getDateFormat() function so that my date format would be only month and date. And i guess i need to remove yearRange as well.

  • dateFormat: "d/M" its gives date & month – Sathish May 6 '19 at 13:29
  • @Sathish I know , how to do it via function getDateFormat() instead of hardcoding it – summu May 6 '19 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.