Skip to main content

Force Custom Text field to uppercase

More
6 years 14 hours ago #324457 by nevillematthews
-- url of the page with the problem -- : www.mathost3.co.uk/lou4
-- HikaShop version -- : 4.4.0
-- Joomla version -- : 3.9.1
-- PHP version -- : 7.3.21
-- Browser(s) name and version -- : Firefox Developer 82.0b5(64-bit)

Hi

How do I force a Custom Text field to uppercase?

I don't really want to use Regex as this only reports an error, I would like the field to just save to uppercase but preferably only show upper case when typing.

Thank you

Neville Matthews

Please Log in or Create an account to join the conversation.

More
6 years 2 hours ago #324470 by nicolas
Hi,

You can add CSS code for that using text-transform: uppercase; on the input field so that the text appears uppercase in the input field.
Now with that, the text will appear uppercase in the input but won't be saved as uppercase.
You would need to also either:
- add a similar CSS to the area where the value is used to have it appear as uppercase
- add some javascript to the page where you have the input to force the uppercase while the text is being typed

Now a simpler approach would be to force uppercase with the pattern attribute in your custom field:
pattern="[A-Z]*"

Here is a page which discuss the different solutions:
www.the-art-of-web.com/html/input-field-uppercase/

Please Log in or Create an account to join the conversation.

More
5 years 11 months ago #325152 by nevillematthews
Hi Nicolas

when I enter exactly this --> pattern="[A-Z]*" including the quotes in the Custom Field "Attributes" field and try to save it I get the following error message:-

Error Saving
Please specify a correct attribute

Thank you

Neville Matthews

Please Log in or Create an account to join the conversation.

More
5 years 11 months ago #325154 by nicolas
Hi,

I think that the issue is that the star character has not been authorized.
Change the line:
Code:
if(!preg_match('#^([a-z0-9_-]+ *= *"[\p{L}\p{N}\p{Z}\p{S}\p{M} :\-;\(\)\{\}\[\]\']+" *)* *$#i', $fieldOptions['attribute'])){
to:
Code:
if(!preg_match('#^([a-z0-9_-]+ *= *"[\p{L}\p{N}\p{Z}\p{S}\p{M} \+\*:\-;\(\)\{\}\[\]\']+" *)* *$#i', $fieldOptions['attribute'])){
in the file administrator/components/com_hikashop/classes/field.php and try again. It should let you do it then.

Please Log in or Create an account to join the conversation.

Time to create page: 0.163 seconds
Powered by Kunena Forum