Jump to content

Edit History

4presta

4presta

Hi.

You can also enter a number in the text field.
All you have to do is add javascript, which does not allow you to enter anything other than the range 0..9
For example, you add the actionAdminControllerSetMedia hook in the module and map the javascript.

public function hookActionAdminControllerSetMedia($params)
    {
        if ($this->context->controller->php_self == 'AdminProducts' && Tools::getValue('id_product'))
        {
            $this->context->controller->addJs(_PS_MODULE_DIR_.$this->name.'/views/js/admin/adminProduct.js');
        } 
    }

and javascript:

$(document).ready(function() {
    /* text field => my_text_field */
    $('[name=my_text_field]').keypress(function (e) {
        var charCode = (e.which) ? e.which : e.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
    });
});

 

4presta

4presta

You can also enter a number in the text field.
All you have to do is add javascript, which does not allow you to enter anything other than the range 0..9
For example, you add the actionAdminControllerSetMedia hook in the module and map the javascript.

public function hookActionAdminControllerSetMedia($params)
    {
        if ($this->context->controller->php_self == 'AdminProducts' && Tools::getValue('id_product'))
        {
            $this->context->controller->addJs(_PS_MODULE_DIR_.$this->name.'/views/js/admin/adminProduct.js');
        } 
    }

and javascript:

$(document).ready(function() {
    /* text field => my_text_field */
    $('[name=my_text_field]').keypress(function (e) {
        var charCode = (e.which) ? e.which : e.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
    });
});

 

×
×
  • Create New...