Question

I have created custom attribute in Magento 1.9.3.

$pro_attribute = [
    'input' => 'text',
    'type' => 'int',
    'label' => 'Pro Position',
    'visible' => true,
    'required' => true,
    'visible_on_front' => true,
    'unique' => true,
    'searchable' => true,
    'filterable' => true,
    'validate' => true,
    'class' => 'validate-number',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//SCOPE_STORE,
];

Field is sucessfully created and has the "required entry" validation. How can I add the "number" validation?

Was it helpful?

Solution

try adding :

'frontend_class' => 'validate-number'

OTHER TIPS

Try this,

I tried out side it's working fine

<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute  = array(
    'group'                => 'General Information',
    'type'              => 'int',//can be int, varchar, decimal, text, datetime
    'backend'           => '',
    'frontend_input'    => '',
    'frontend'          => '',
    'label'             => 'Pro Position',
    'input'             => 'text', //text, textarea, select, file, image, multilselect
    'default' => array(0),
    'class'             => 'validate-number',
    'source'            => 'eav/entity_attribute_source_text',//this is necessary for select and multilelect, for the rest leave it blank
    'global'             => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,//scope can be SCOPE_STORE or SCOPE_GLOBAL or SCOPE_WEBSITE
    'visible'           => true,
    'frontend_class'     => 'validate-number',

    'user_defined'      => true,
    'default'           => '',
    'position'            => 100,//any number will do
);

$installer->addAttribute('catalog_category', 'pro_position', $attribute);
$installer->endSetup();
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top