Force Custom Text field to uppercase

  • Posts: 31
  • Thank you received: 1
  • Hikashop Business
3 years 6 months ago #324457

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

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
3 years 6 months ago #324470

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.

  • Posts: 31
  • Thank you received: 1
  • Hikashop Business
3 years 5 months ago #325152

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.

  • Posts: 81509
  • Thank you received: 13064
  • MODERATOR
3 years 5 months ago #325154

Hi,

I think that the issue is that the star character has not been authorized.
Change the line:

if(!preg_match('#^([a-z0-9_-]+ *= *"[\p{L}\p{N}\p{Z}\p{S}\p{M} :\-;\(\)\{\}\[\]\']+" *)* *$#i', $fieldOptions['attribute'])){
to:
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.057 seconds
Powered by Kunena Forum