Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Attribute type "Number" (like text but..)

Attribute type "Number" (like text but..)

Views: 1,027

Results 1 to 6 of 6
19 Feb 2014, 3:50 PM
#1
vandijkstef avatar

vandijkstef

New Zenner

Join Date:
Feb 2014
Location:
Amsterdam, Netherlands
Posts:
9
Plugin Contributions:
0

Attribute type "Number" (like text but..)

I'm trying to get a new option type in Zen Cart (ADMIN/options_name_manager.php (Option Type), but I can't seem to find the right files to add/edit.

On a native ZC install, you can add an options name and set the option type for this to text, dropdown, radio, checkbox, file etc. I would like to have a specific one that only accepts numbers.

In the database I've already added a Option Type called "numbers" and this shows in the dropdown. But right now, Zen Cart doesn't know how to handle this, and it requires me to add option values and shows the content as radio buttons.

I want to have this new custom field "Number" behave like "Text". (which require no further option values to work).

What file is telling Zen Cart how to render this? If I know this file, I'll probably manage.

I already know how to make that field only listen to numbers, using HTML5 or JS, so I don't need any info regarding this.

Thanks!

19 Feb 2014, 4:31 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,097
Plugin Contributions:
56

Re: Attribute type "Number" (like text but..)

A product's attributes (the combination of an "Option Name" and an "Option Value") are formatted for display by /includes/modules/attributes.php. You should copy this file to /includes/modules/YOUR_TEMPLATE/attributes.php, if it's not already present, and make your edits there.

21 Feb 2014, 6:59 AM
#3
vandijkstef avatar

vandijkstef

New Zenner

Join Date:
Feb 2014
Location:
Amsterdam, Netherlands
Posts:
9
Plugin Contributions:
0

Re: Attribute type "Number" (like text but..)

This is what I needed. Thanks!

26 Mar 2014, 9:54 AM
#4
vandijkstef avatar

vandijkstef

New Zenner

Join Date:
Feb 2014
Location:
Amsterdam, Netherlands
Posts:
9
Plugin Contributions:
0

Re: Attribute type "Number" (like text but..)

In the end it was easier to add this to tpl_modules_attributs.php in the template folder:

<script type="text/javascript">
$(document).ready(function() {
    $("#attrib-7-0").keydown(function(event) {
        // Allow: backspace, delete, tab, escape, enter and .
        if ( $.inArray(event.keyCode,[46,8,9,27,13,190]) !== -1 ||
             // Allow: Ctrl+A
            (event.keyCode == 65 && event.ctrlKey === true) || 
             // Allow: home, end, left, right
            (event.keyCode >= 35 && event.keyCode <= 39)) {
                 // let it happen, don't do anything
                 return;
        }
        else {
            // Ensure that it is a number and stop the keypress
            if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
                event.preventDefault(); 
            }   
        }
    });
});
</script>
27 Mar 2014, 12:17 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Attribute type "Number" (like text but..)

Is it going to be a problem for you that someone can defeat this by disabling javascript, and have a non-numeric value entered for the attribute?

27 Mar 2014, 7:55 AM
#6
vandijkstef avatar

vandijkstef

New Zenner

Join Date:
Feb 2014
Location:
Amsterdam, Netherlands
Posts:
9
Plugin Contributions:
0

Re: Attribute type "Number" (like text but..)

Nope it won't. We sell house number signs, after the order it will be checked & processed by hand. The customers that currently make this mistake are not power users. And if so, we will e-mail the customer in this specific case.

I agree that a HTML 5 number input field would be even better.