Page 1 of 1
text option field wont accept number zero
Posted: Fri Mar 03, 2017 11:10 pm
by gwp
I have Version 2.3.0.2
when i create a text type option. and try to enter the number "0". it says to me
"Text required"
Entering any other number works fine.
Please be aware this is just entering a single digit zero, which id like to do. all other single digit numbers work fine.
Also, if i enter 01 or 10, it works fine
Re: text option field wont accept number zero
Posted: Sat Mar 04, 2017 12:42 am
by thekrotek
That's because it check for empty field and zero is empty in PHP. You can change it in the code to check for "", which will let you enter zero values.
Re: text option field wont accept number zero
Posted: Sat Mar 04, 2017 5:55 pm
by gwp
Thanks for prompt reply.
Could you tell me where to change the code please.
Re: text option field wont accept number zero
Posted: Sat Mar 04, 2017 6:15 pm
by thekrotek
That depends on where you see this error and which error exactly. There's no "Text required" message in default OpenCart.
Re: text option field wont accept number zero
Posted: Sat Mar 04, 2017 6:25 pm
by gwp
its when i create an "option" and choose the input type "text"
The "???? required" message changes as to what you have called that text option., eg: a text option i have called "age", would display "age required".
Re: text option field wont accept number zero
Posted: Sat Mar 04, 2017 8:17 pm
by thekrotek
So on WHICH PAGE does it happen exactly? In admin on product editing page zero value in text option is saved properly.
Re: text option field wont accept number zero
Posted: Sat Mar 04, 2017 10:43 pm
by gwp
If i go to admin>options and add an option of text type, called score.
i add the score option to my product.
i visit the product (on the product page), where i can buy the product.
the option is listed and its there where it wont accept zero
Thanks
Re: text option field wont accept number zero
Posted: Sun Mar 05, 2017 2:10 am
by thekrotek
Ah, that's a bit tricky to find. This is a JavaScript check for field with "required" class, somewhere in the core. I did a quick search for "required", "!required" and ".required", but didn't find anything suitable. So try to search for "required" in OC original package and look for any conditions, where this class is checked. The right code to replace with should be this:
Or something like that, depending on what you will find. It'll look ONLY for empty value, but exclude zero.
I'm too lazy to do the digging myself :-)
Re: text option field wont accept number zero
Posted: Sun Mar 05, 2017 2:19 am
by gwp
Lol. You have no need to. Ill do the digging myself.
Many many thanks for steering me in right direction
Re: text option field wont accept number zero
Posted: Sun Mar 05, 2017 10:48 pm
by gwp
well, i think I have found it. but cant get it to work.
catalog\view\theme\default\template\product\product.tpl
i found this..
Code: Select all
<?php if ($option['type'] == 'text') { ?>
<div class="option form-group<?php echo ($option['required'] ? ' required' : ''); ?>">
<label class="control-label" for="input-option<?php echo $option['product_option_id']; ?>"><?php echo $option['name']; ?></label>
<input type="text" name="option[<?php echo $option['product_option_id']; ?>]" value="<?php echo $option['value']; ?>" placeholder="<?php echo $option['name']; ?>" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control" />
</div>
ive tried various combinations but no joy.
Im not programmer, so any clues pls
Thanks
Re: text option field wont accept number zero
Posted: Sun Mar 05, 2017 10:52 pm
by thekrotek
Like I said above, it's in JavaScript, not in PHP. You've found a wrong code and this is why it doesn't work.