3

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!

dotancohen
1,1306 silver badges21 bronze badges
asked May 1, 2013 at 23:41
1
  • 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... Commented May 8, 2013 at 21:28

2 Answers 2

3

Tested and working:

'frontend_class' => 'validate-number'

Here you can find further reference: Adding Magento custom attributes through setup scripts with all the validation options

answered Jul 7, 2014 at 10:58
2

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

answered May 2, 2013 at 2:31
1
  • 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. Commented May 2, 2013 at 13:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.