support

Author Topic: Conditional options?  (Read 9440 times)

Offline rnkwoodworks

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-0
    • View Profile
Conditional options?
« on: February 06, 2022, 08:12:27 AM »
Coming from Prestacart due to it's limitations on options.

We sell things like cutting boards, plaques, etc and offer custom laser engraving at an additional charge.

It's great that I can offer this in AbanteCart but I also need to get input about what they want engraved.
I have an input box but unless people realize they HAVE to choose an engraving option, I don't want them assuming anything.

Is there a way I can have a text input conditional based on whether they chose engraving or not?

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • Karma: +284/-2
    • View Profile
Re: Conditional options?
« Reply #1 on: February 07, 2022, 01:02:40 AM »
Hello.
There is no such feature but it is possible to add the HTML block to the product page layout with small javascript code to make the text input required if for example checkbox is selected.
Something like https://stackoverflow.com/questions/41104324/make-input-text-field-required-if-checkbox-was-selected

Offline rnkwoodworks

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-0
    • View Profile
Re: Conditional options?
« Reply #2 on: February 07, 2022, 04:36:32 AM »
Thanks so much for the answer but I figured out an easier way to do it.

Instead of a select box with engraving options and then an input with what they want engraved, I am just going to have several inputs that explain what they're for. I believe this leaves no doubt as to what they're getting. Something like the screen snippet attached.

It's great that AbanteCart updates the total once they type something in any of the boxes.


Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • Karma: +284/-2
    • View Profile
Re: Conditional options?
« Reply #3 on: February 07, 2022, 05:33:16 AM »
You can also add a regex pattern to validate or limit the input

Offline rnkwoodworks

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-0
    • View Profile
Re: Conditional options?
« Reply #4 on: February 07, 2022, 06:26:58 AM »
You can also add a regex pattern to validate or limit the input

Yea I appreciate the idea but I just spent an hour trying to figure out the regular expressions to use but had no success. I tried downloading Expresso but it hasn't helped. I tried /[a-zA-Z]+ [a-zA-Z]+/i but it allows more than two words.

 Eventually I'll figure it out.

Offline rnkwoodworks

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-0
    • View Profile
Re: Conditional options?
« Reply #5 on: February 07, 2022, 06:50:08 AM »
Ok I found this elsewhere on the web and it seems to work. Just posting it for anyone else that might need similar down the road. Perhaps there are things in this Regex that will prove problematic but it's on the right track.

/^(?:\w+\W+){0,1}(?:\w+)$/

Replace the "1" in {0,1} with the number of words you want to allow over the first. In other words mine allows 2 words. To allow 6 words, change the 1 to a 5 like {0,5}

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • Karma: +284/-2
    • View Profile
Re: Conditional options?
« Reply #6 on: February 07, 2022, 07:08:25 AM »
Thank you rnkwoodworks

Offline rnkwoodworks

  • Newbie
  • *
  • Posts: 8
  • Karma: +2/-0
    • View Profile
Re: Conditional options?
« Reply #7 on: February 07, 2022, 08:23:29 AM »
Issue... the above regex only allows ordering IF you input two words into the option. If not, it rejects the order. Same happens if I put a regex into the 10 word option.

I thought if an option wasn't marked required, the regex wouldn't even come into play?

Sorry about all this.

 

Powered by SMFPacks Social Login Mod