Search code examples
magentoattributesadminhtml

How to set maximum value of date attribute in Magento?


I want to set maximum value of "Date of Birth" (dob) attribute of the customer.

I want to set this date only earlier than today (not for future). After change I want to have JS validation on adminhtml backend in customer edit screen.

I want to update this attribute in setup scripts within my module. How to achieve this?

Thanks in advance for your help.


Solution

  • You have to code it. Admin panel uses Prototype Validation: you can extend by creating a custom JS file with your validation rules, in the form:

     if(Validation) {
       Validation.add AllThese ([
        ['validate-dob',    // class/rule name
         'DOB cannot be in the future',  // Error message
          function (v) {
             //  TODO: validation of input, 'v' being the input.
             // return true (input is ok) or false
         }]
          // more rules here, if needed..
      ])};
    

    Then dynamically add 'validate-dob' class to customer dob input field. You can do it in this file too. Add your custom file to be loaded in the admin theme in adminhtml default layout main.xml.