Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    107
    Plugin Contributions
    1

    Default 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!!

  2. #2
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default 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...

  3. #3
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    107
    Plugin Contributions
    1

    Default Re: Uppercase only attributes

    Quote Originally Posted by mc12345678 View Post
    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.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

    Default Re: Uppercase only attributes

    Quote Originally Posted by jwlamb View Post
    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...

  5. #5
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default 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:
    Code:
    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).

  6. #6
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    107
    Plugin Contributions
    1

    Default Re: Uppercase only attributes

    Quote Originally Posted by balihr View Post
    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:
    Code:
    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

  7. #7
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    107
    Plugin Contributions
    1

    Default 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.

  8. #8
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    107
    Plugin Contributions
    1

    Default Re: Uppercase only attributes

    Quote Originally Posted by jwlamb View Post
    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.

  9. #9
    Join Date
    Oct 2008
    Location
    Croatia
    Posts
    1,542
    Plugin Contributions
    19

    Default Re: Uppercase only attributes

    Quote Originally Posted by jwlamb View Post
    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:
    Code:
    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);
    Quote Originally Posted by jwlamb View Post
    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.

    Quote Originally Posted by jwlamb View Post
    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?

  10. #10
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    107
    Plugin Contributions
    1

    Default Re: Uppercase only attributes

    Quote Originally Posted by balihr View Post
    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.

    Quote Originally Posted by balihr View Post
    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.


    Quote Originally Posted by balihr View Post
    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!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v155 Uppercase JPG image files 403 Forbidden
    By enchanted1 in forum Setting Up Categories, Products, Attributes
    Replies: 10
    Last Post: 17 Jul 2018, 08:52 PM
  2. v155 UPPERCASE and Lowercase words in SQL
    By adb34 in forum General Questions
    Replies: 3
    Last Post: 11 Sep 2017, 10:01 AM
  3. v139h Uppercase problem
    By gotyed in forum General Questions
    Replies: 6
    Last Post: 9 Mar 2012, 01:56 AM
  4. Customer information with uppercase on first letter
    By Svanis in forum Basic Configuration
    Replies: 8
    Last Post: 1 Aug 2006, 03:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR