Tell me more ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I have a shipping plugin that creates 3 product attributes, namely length, width and height.

I have the following code in my install script:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$setup->addAttribute('catalog_product', 'length', array(
    'group'         => 'General',
    'input'         => 'text',
    'type'          => 'text',
    'label'         => 'Length',
    'backend'       => '',
    'visible'       => TRUE,
    'required'      => TRUE,
    'user_defined'  => TRUE,
    'searchable'    => FALSE,
    'filterable'    => FALSE,
    'comparable'    => FALSE,
    'visible_on_front' => FALSE,
    'visible_in_advanced_search'  => FALSE,
    'is_html_allowed_on_front' => FALSE,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

I wish add "Decimal Number" "Input Validation for Store Owner".

I tried changing type to 'int', but that didn't seem to work.

Using Magento Version 1.7.0.2. Here is the project on github and here is the Install File

Any help would be appreciated!

share|improve this question
I ended up changing the type to "decimal", which forces a decimal on save, however, it does not warn the admin that the values are entered incorrectly, and simply changes it to 0 if text was entered... – Xethron May 8 at 21:28

1 Answer

try adding :

'class' => 'validate-number' 

That will hook into Magento's prototype driven Validation javascript. Ref http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/installing_custom_attributes_with_your_module

share|improve this answer
Tried adding the class, and also worked through the examples on the link you gave me, but it doesn't seem to work. In that link they also seem to be using a different function. Might be for an older Magento? I'm using Magento ver. 1.7.0.2. – Xethron May 2 at 13:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.