News:

AbanteCart v1.4.2 is released.

Main Menu

Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

[SOLVED] Product Option don't accept value "0"

Started by toulip, November 29, 2020, 06:19:42 AM

Previous topic - Next topic

toulip

Hello there :)

I have a product which need to have a value specified by the customer.
This value can be between -30 and 100.
I tried with a textarea and a regex /^-?[1-9]\d{0,2}$|^0$/
Everything works fine except for the value "0"

I also tried with an input instead of a textarea.

The regex is good, and not the problem. I think it comes from the way the script is written but I can't find it to edit it.

Is there someone here with a solution ?

Thank you and have a nice day !

abolabo

hi.
Why do you use digits set [1-9] instead [0-9] ?
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

toulip

Hello, thank you for your reply

Because "-0" is not a valid value ^^

But as I said, I don't think it comes from the regex, I tried multiple regex and I have always the issue with 0.
In fact, if I don't set regex at all, but set the "required" field only I still can't enter the value "0" and all the other value work.

abolabo

what about this pattern?

^(-?\d+\.)?-?\d+$
"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

toulip

Still doesn't work unfortunately :/

As I mentionned in the previous post, if I simply don't put any regex and set "required field " to true, I stil can't enter "0"
By the way, I forgot to mention that the error message displayed when entering "0" is "error_required_options" and not the regex error message :/
This is not a regex issue, but a script issue I think

Tahnk you for your time :)

maxter

I think you need this ^-?[1-9]\d{0,2}$|^-0$

You can test your regex in here https://www.regexpal.com

toulip

Thank you for your answer. :)

"-0" is not a value I want to be correct

The value specified by the customer need to be between -30 and 100. "-0" does not exist.

So ^-?[1-9]\d{0,2}$|^0$ is correct as you can enter a negative value, 0 or something superior to 0 and 3 digit longs

The regex is not the issue. Do you know where I can find the script that handle the product option validation ? It certainly come from there :)



abolabo

"No one is useless in this world who lightens the burdens of another."
― Charles Dickens

toulip

#8
Thank you very much !

Now that I had acces to the code it's fixed.
The product option check use the function empty() which consider the string "0" empty so it's not valid.

I fixed by editing line 1338

unfortunately I can't post my fix as the forum rules consider this a link....
But it is a simple check if option != 0 before the empty check

Forum Rules Code of conduct
AbanteCart.com 2010 -