space10-community / conversational-form

Turning web forms into conversations
https://space10-community.github.io/conversational-form/
MIT License
3.8k stars 773 forks source link

Conditional-Flow Multiple OR'd conditions? #137

Open AfaanBilal opened 7 years ago

AfaanBilal commented 7 years ago

Hi,

Can we have multiple conditions but the logic OR instead of AND?

<input
    type="text"
    cf-questions="Question to ask.."
    cf-conditional-cfc-hello="world" /> <!-- will check for name attribute cfc-hello -->
    cf-conditional-cfc-world="hello" /> <!-- will check for name attribute cfc-world -->

The above example question will only be shown when BOTH the conditions:

Is there a way to make it so that even if only one of the multiple conditions is met, the question is still shown?

Thanks!

felixknox commented 7 years ago

@AfaanBilal would this work: cf-conditional-cfc-hello="||world" here the conditional would go through if "no value" and value "world". I can add it tomorrow.

AfaanBilal commented 7 years ago

@felixnielsen Thanks for responding! Wouldn't this go through if both cfc-hello and cfc-world are left blank? I need at least one of them to have the required value.

danielfriis commented 7 years ago

@AfaanBilal Interesting case. Do you have any suggestions for how you'd like a solution to work?

AfaanBilal commented 7 years ago

@danielfriis Maybe something like this could be done:

<input
    type="text"
    cf-questions="Question to ask.."
    cf-or-conditional-cfc-hello="world" /> <!-- will check for name attribute cfc-hello -->
    cf-or-conditional-cfc-world="hello" /> <!-- will check for name attribute cfc-world -->

The cf-or-conditional could be evaluated in the same way as the existing cf-conditional except that multiple cf-or-conditional should be joined with an OR || instead of an AND &&.

Would that be possible?

Thanks!

sajadshafizadeh commented 6 years ago

Has someone found any solution to do OR on multiple conditions?

jenssogaard commented 6 years ago

Hi @AfaanBilal I have been testing your PR and playing around with it. However, I do see an issue when we start combining cf-conditional (&&) with the cf-or-conditional (||). As I see it any cf-conditionals on the same tag as cf-or-conditional will be ignored, correct? Do you have any ideas as to how we could solve that?

cf-conditional-cfc-beer="ipa"
cf-or-conditional-cfc-intro="yes"
cf-or-conditional-cfc-please="yes"
AfaanBilal commented 6 years ago

Hi @jenssogaard Yes, you're right. So, the behavior that we desire should be that all cf-conditional tags must evaluate to TRUE and at least one of the cf-or-conditional tags must evaluate to TRUE for the form tag to be shown, right?

AfaanBilal commented 6 years ago

Hi @jenssogaard I've pushed a new commit to the pull request that solves this issue implementing the logic as in my comment above.

Thanks!

reid-markel commented 5 years ago

I'm still having a conditional problem, I read the docs and followed the instructions for multiple conditionals and no dice. Is this a bug that's going to be fixed in the near future?