AbanteCart Community

Shopping Cart Operations => Support => General Support => Topic started by: David Veganhauser on May 04, 2020, 04:44:11 AM

Title: Maximum Length of custom field
Post by: David Veganhauser on May 04, 2020, 04:44:11 AM
Hello,

Is there a way I can limit the number of characters for a custom field that I have added to my form?

For instance, can I limit this field shown to 100 characters?

Thank you in advance.
Title: Re: Maximum Length of custom field
Post by: Basara on May 04, 2020, 06:45:14 AM
Hello. Fill the regex pattern https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s09.html
Title: Re: Maximum Length of custom field
Post by: David Veganhauser on May 04, 2020, 10:57:50 AM
Hi, I went to the page and looked over the article. It was a bit confusing as it was not specific enough for me to follow (sorry)

So I tried this

/^.{1,100}$/

And it doesnt work

Ideas?
Title: Re: Maximum Length of custom field
Post by: dvagner on May 05, 2020, 02:22:09 AM
I try your regex - they work fine.
Provide more information: Abantecart Version, browsers for test, have you errors in browser console? errors in abantecart log or php? etc.
Title: Re: Maximum Length of custom field
Post by: David Veganhauser on May 05, 2020, 03:27:57 AM
Hi, thanks for your reply

I was not getting errors, just nothing was happening. I could keep typing and I got no message.  Maybe I have just not implemented it correctly? see the screenshot I have posted below

AbanteCart Version 1.2.15
Google Chrome Version 81.0.4044.129 (Official Build) (64-bit)
Title: Re: Maximum Length of custom field
Post by: dvagner on May 05, 2020, 05:06:43 AM
Verify start after click on "Add to Cart"
On typing used html attribute 'pattern'
<input type="text" name="option[354]" id="option354" value="" placeholder="" class="form-control " data-attribute-value-id="" pattern="^.{1,100}$" title="Some error text">
Title: Re: Maximum Length of custom field
Post by: David Veganhauser on May 05, 2020, 06:15:55 AM
Thank you for writing me back.. I understand html and css, but in the context of using AbanteCart or other layers like this, I admit I am lost since I have never worked with them before.

I do not see an element type that allows me to write a custom piece of html. Are you saying I should modify the tpl file?  Sorry for the stupid questions in advance!

Verify start after click on "Add to Cart"
On typing used html attribute 'pattern'
<input type="text" name="option[354]" id="option354" value="" placeholder="" class="form-control " data-attribute-value-id="" pattern="^.{1,100}$" title="Some error text">
Title: Re: Maximum Length of custom field
Post by: dvagner on May 06, 2020, 03:09:57 AM
You can change tpl (for custom JS validation) or create extension with hook's to add php validation.
Title: Re: Maximum Length of custom field
Post by: David Veganhauser on May 06, 2020, 03:35:16 AM
THank you for your reply!