Question

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.

Was it helpful?

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.

OTHER TIPS

You could create your own custom validation,

var theForm = new VarienForm('theForm', true);
Validation.add('validate-dob','You failed to enter baz!',function(the_field_value){
    if(check date)
    {
        return true;
    }
    return false;
});

see How to add a custom validation to Magento prototype

Then including the js file using local.xml

 <adminhtml_sales_order_view>
    <reference name="head">
        <action method="addItem"><type>skin_js</type><name>path/to/validation_dob.js</name></action>
    </reference>
</adminhtml_sales_order_view>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top