Option-dependent text field

  • Posts: 8
  • Thank you received: 1
  • Hikashop Business
3 days 19 hours ago #367694

-- HikaShop version -- : 6.0.0
-- Joomla version -- : 5.3.1
-- PHP version -- : 8.4.7
-- Browser(s) name and version -- : Safari 18.5
-- Error-message(debug-mod must be tuned on) -- : No error message

Is it possible to enable the "Text" text field only if the "Greeting Text" option is set to "Ja" (yes)? With the default setting of "Nein" (no), it should not be possible to enter text.

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

  • Posts: 84025
  • Thank you received: 13614
  • MODERATOR
3 days 16 hours ago #367695

Hi,

There are two ways to do it:

- The hard way is to add a bit of custom javascript to listen to the dropdown selection being changed and then hide / display the input field. This requires a bit of development. Here is a starting point:
www.hikashop.com/support/forum/product-c...culation.html#344613
Note however that if the customer enters something in the custom item field and then select "no" in the dropdown and the custom item field is hidden on the page, it will still be taken into account by HikaShop and displayed in the cart / order / invoice. So you would have to also empty the field when "no" is selected.
Another limitation of this solution is that you can make the custom item field required. Because if you do, the system won't let you proceed when "no" is selected.
While it has constraints and is not so easy to do, it is possible to cobble something together with that solution.

- Instead of an option for the extra fee, I would recommend having another custom field of the table "item" and of the type "single dropdown". That way, in the text custom field, you can use the "display limited to" setting to have the system automatically hide / display the text field based on the selection in the dropdown. The "required" mechanism also take into account that "display limited to" setting.
In the past, the limitation of this solution was that you couldn't change the price of the product based on what was selected / entered in the custom item fields. However, a few years back we released the "price calculations" plugin :
www.hikashop.com/support/forum/product-c...culation.html#344613
With it, you can use a formula to modify the price with the calculation of a formula with tags. In your case, you could have the value "0.0" for the "no" choice, and the value "15" for the "yes" choice of your dropdown. And then, you could use the formula:
{price}+{xxx}
where xxx would be the column name of the custom field for the yes / no choice.

In fact, you could even do without the yes / no custom field, and just have the text field. Then, you would use the formula:
{price}+15
with the condition
strlen({yyy}) > 0
where yyy would be the column name of the text custom field.
That way, the system would automatically add the 15€ extra fee to the total amount once the user enters something in the text field.

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

Time to create page: 0.050 seconds
Powered by Kunena Forum