If this is your first visit, check our documentation. To post, register or login.
Forums / Setting Up Categories, Products, Attributes / Uppercase only attributes

Uppercase only attributes

Started by jwlamb on 4 Jun 2022, 8:56 PM · Views: 4,267

Results 1 to 15 of 15
4 Jun 2022, 8:56 PM
#1
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Uppercase only attributes

Good afternoon,

My website sells custom name tags and patches. The customer can add the text to the attribute and then the text gets added to their product. But on certain items I only want them to be able to use uppercase letters. I found one answer that added a line to the stylesheet, but it did not make the attribute uppercase. Is there a way to change it so certain attributes can only be capital letters? I don't want all attributes uppercase as some items can have lower case letters. Thank you!!

5 Jun 2022, 4:24 AM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Uppercase only attributes

Are you wanting to control just the visual display of those attributes as all capital, or do you want to store the text with the content in all capitals?

The first could be done with css on every page where those attributes would be displayed, the second could use jquery and or internal processing to force the data to be all capital letters for the desired attribute(s).

Basically the attributes option name's id value is what will be important to know so that when encountered the data of the sub attribute would be forced to go through that code.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

5 Jun 2022, 7:22 PM
#3
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

mc12345678:

Basically the attributes option name's id value is what will be important to know so that when encountered the data of the sub attribute would be forced to go through that code.

I just want them to only be able to make a purchase with using uppercase letters for some items, but not all. So when they type it only permits uppercase letters in the attribute text box. Some items can have lowercase letters, so this is limited to just some attributes, particularly Option Name "Wording" Option ID 110.

8 Jun 2022, 6:47 PM
#4
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: Uppercase only attributes

jwlamb:

I just want them to only be able to make a purchase with using uppercase letters for some items, but not all. So when they type it only permits uppercase letters in the attribute text box. Some items can have lowercase letters, so this is limited to just some attributes, particularly Option Name "Wording" Option ID 110.

I've been thinking about this more, it appears that a two pronged approach may be best. On one hand it's to use jquery to update the onscreen content to all capital letters while typing the text, but then for those without accepting enabled to use includes/extra_cart_actions to process the text attributes to uppercase before the shopping cart stores the values. Ideally both approaches would use a single file or repository to I identify the option names that are to be all capital...

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

11 Jun 2022, 11:22 AM
#5
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: Uppercase only attributes

A really simple way of doing this is to use javascript or jQuery. It's probably not the best way, but it's simple. A much better alternative would be to use CSS and convert to uppercase using php, but it's not as simple as this.

You can create a new file in includes/modules/pages/product_info/jscript_capitals.js and put this inside:

function attribUppercase(e)
{
	var charInput = e.keyCode;
	if((charInput >= 97) && (charInput <= 122)) { // lowercase
		if(!e.ctrlKey && !e.metaKey && !e.altKey) { // no modifier key
			var newChar = charInput - 32;
			var start = e.target.selectionStart;
			var end = e.target.selectionEnd;
			e.target.value = e.target.value.substring(0, start) + String.fromCharCode(newChar) + e.target.value.substring(end);
			e.target.setSelectionRange(start+1, start+1);
			e.preventDefault();
		}
	}
}
window.onload = function() {
	document.getElementById("attrib-110-0").addEventListener("keypress", attribUppercase, false);
}

Notice the part in red - check if your element has that exact ID and change if needed (right-click the input field -> Inspect Element).

My site - Pro ZC Help
My portfolio | My plugins

12 Jun 2022, 4:43 PM
#6
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

balihr:

A really simple way of doing this is to use javascript or jQuery. It's probably not the best way, but it's simple. A much better alternative would be to use CSS and convert to uppercase using php, but it's not as simple as this.

You can create a new file in includes/modules/pages/product_info/jscript_capitals.js and put this inside:

function attribUppercase(e)
{
var charInput = e.keyCode;
if((charInput >= 97) && (charInput <= 122)) { // lowercase
if(!e.ctrlKey && !e.metaKey && !e.altKey) { // no modifier key
var newChar = charInput - 32;
var start = e.target.selectionStart;
var end = e.target.selectionEnd;
e.target.value = e.target.value.substring(0, start) + String.fromCharCode(newChar) + e.target.value.substring(end);
e.target.setSelectionRange(start+1, start+1);
e.preventDefault();
}
}
}
window.onload = function() {
document.getElementById("attrib-110-0").addEventListener("keypress", attribUppercase, false);
}

> Notice the part in red - check if your element has that exact ID and change if needed (right-click the input field -> Inspect Element).

This worked!! My only follow on question is how to add multiple attributes to do the same thing?  Attribute # 108 and 112
12 Jun 2022, 4:55 PM
#7
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

Would it be easier to have a new Option Type (checkbox, radio, text, CAPITAL only text)? Then all attributes set to "CAPITAL only text" could quickly and easily be changed to uppercase only? Then there wouldn't be a need to adjust a js file as you go.

12 Jun 2022, 5:08 PM
#8
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

jwlamb:

This worked!! My only follow on question is how to add multiple attributes to do the same thing? Attribute # 108 and 112

I should note, only partially worked. Mobile versions of the site still allow lower case.

12 Jun 2022, 6:11 PM
#9
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: Uppercase only attributes

jwlamb:

This worked!! My only follow on question is how to add multiple attributes to do the same thing? Attribute # 108 and 112
Just duplicate the line with your selector for each item you want to add:

document.getElementById("attrib-110-0").addEventListener("keypress", attribUppercase, false);
document.getElementById("attrib-108-0").addEventListener("keypress", attribUppercase, false);
document.getElementById("attrib-112-0").addEventListener("keypress", attribUppercase, false);

jwlamb:

Would it be easier to have a new Option Type (checkbox, radio, text, CAPITAL only text)? Then all attributes set to "CAPITAL only text" could quickly and easily be changed to uppercase only? Then there wouldn't be a need to adjust a js file as you go.
It probably would be easier, but it would require A LOT of modifications to core files so I won't go into that.

jwlamb:

I should note, only partially worked. Mobile versions of the site still allow lower case.
Not sure because the js file should be loaded always. What template are you using? Do you have a separate mobile-only template? Can you provide a link to the site?

My site - Pro ZC Help
My portfolio | My plugins

13 Jun 2022, 7:08 PM
#10
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

balihr:

Just duplicate the line with your selector for each item you want to add

I tried that, but it only works on one item and not the other.

balihr:

It probably would be easier, but it would require A LOT of modifications to core files so I won't go into that.

I'm still leaning this direction.

balihr:

Not sure because the js file should be loaded always. What template are you using? Do you have a separate mobile-only template? Can you provide a link to the site?

The westminster has it's own mobile version built in as far as I can tell. I don't have anything special set up for it. I pm'd you the links.

Thanks!

13 Jun 2022, 7:40 PM
#11
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: Uppercase only attributes

jwlamb:

I tried that, but it only works on one item and not the other.
Sorry about that. Try this:
Instead of

document.getElementById("attrib-110-0").addEventListener("keypress", attribUppercase, false);

use this

var element = document.getElementById("attrib-110-0");
if(typeof(element) != 'undefined' && element != null){
        document.getElementById("attrib-110-0").addEventListener("keypress", attribUppercase, false);
    }

Of course, duplicate the block for each option. There are ways to make this look nicer using loops, but hey, KISS... :smile:

jwlamb:

I'm still leaning this direction.
This is something you'll either need to figure out yourself or hire someone to do it for you - it's way too much to guide you here.

jwlamb:

The westminster has it's own mobile version built in as far as I can tell. I don't have anything special set up for it. I pm'd you the links.

Thanks!

It's just responsive, it's not a mobile version. Seems to work for me, at least for the product that works on desktop. If you apply the changes mentioned above and clear your cache, it'll probably work on mobile as well.

My site - Pro ZC Help
My portfolio | My plugins

15 Jun 2022, 5:48 AM
#12
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

balihr:

it'll probably work on mobile as well.

:clap: It works on both items now, but sadly not on mobile. I'm happy with it while I work on the new Options Type. Thank you very much for your help!!

15 Jun 2022, 7:45 PM
#13
balihr avatar

balihr

Totally Zenned

Join Date:
Oct 2008
Location:
Croatia
Posts:
1,817
Plugin Contributions:
24

Re: Uppercase only attributes

Ah, yes, you're right - I didn't test on mobile, but instead I used Chrome to emulate a mobile device...

Try this:

var element = document.getElementById("attrib-110-0");
if(typeof(element) != 'undefined' && element != null){
        document.getElementById("attrib-110-0").addEventListener("keydown", attribUppercase, false);
}

keydown should work on mobile as well...

My site - Pro ZC Help
My portfolio | My plugins

20 Jun 2022, 6:15 PM
#14
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

balihr:

keydown should work on mobile as well...

keydown doesn't work on either desktop or mobile.

26 Jun 2022, 4:45 PM
#15
jwlamb avatar

jwlamb

Zen Follower

Join Date:
Jan 2014
Location:
Arizona
Posts:
110
Plugin Contributions:
0

Re: Uppercase only attributes

refreshing