• Resolved castria

    (@castria)


    I have a number field that i only want to appear if a specific checkbox is checked. There doesn’t seem to be a way to set the logic to check this. It always reads the checkbox as true/1/not empty whether it is checked or not, meaning the number field is always visible and no way to conditionaly hide/show it.

    • This topic was modified 2 years, 4 months ago by castria.
    • This topic was modified 2 years, 4 months ago by castria.
Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    Hi, fixed in v.1.4.4. Rule “{checkbox} has any value” should work now.

    Thread Starter castria

    (@castria)

    @wckalkulator Works perfectly, thank you!

    I did notice another bug you may want to be aware of. I also had tried with multi-checkboxes. I wanted to have, for example, 5 checkboxes and a number field that becames visible for each checkbox. So, if checkbox 1, 3 and 4 were checked, number fields 1, 3 and 4 would become visible. This didn’t work for me using manual values, “is empty” or “has any value”. If you can get this working it’d be a big help for a client i currently have and I know you don’t do a paid version but i’ll hapilly give a donation if you give me a few days.

    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    Hi, I will do it in 12 h. Thanks for this information

    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    @castria multi checkbox has beed fixed in 1.4.5. For example: {multi_cb} has values: 10 -> Option A, 20 -> Option B. So the visibility rule for a first number field will be “{multi_cb} == 10” and the second one “{multi_cb} == 20”

    Thread Starter castria

    (@castria)

    Thank you so much. Incredible support for a free plugin. That works great now.

    I’ve now encountered a new problem. In price calculation, I chose “Price Add-ons”. I want it to be:

    if {multi_cb} == 1, add {number_field_1} * 100
    if {multi_cb} == 2, add {number_field_2} * 185
    if {multi_cb} == 3, add {number_field_3} * 220

    but doing this doesn’t work and i get the following message on the product screen:

    “Total Variable “multi_cb” is not valid around position 1 for expression “multi_cb == 1”. Did you mean “number_field_1″?”

    It does work if my conditional checks if the number fields are >= 1 but the problem there is they have a minimum value of 1, so if the checkbox is selected, it would add the price, but if it was then deselected, it becomes invisible but the price doesn’t go back to 0, so it only works properly if the price is only set to be added IF the relevant checkbox is checked in the multi checkbox.

    • This reply was modified 2 years, 4 months ago by castria.
    • This reply was modified 2 years, 4 months ago by castria.
    • This reply was modified 2 years, 4 months ago by castria.
    • This reply was modified 2 years, 4 months ago by castria.
    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    Multi checkbox is tricky, because it returns fixed price or sum/min/max of selected values. Try something like if {num1} > 0 add {num1}*100.

    My idea was to make function something like is_selected({multicb}, 1), maybe you have better idea?

    Thread Starter castria

    (@castria)

    My idea was to make function something like is_selected({multicb}, 1), maybe you have better idea?

    Yeah this is my thinking for what should be the simplest solution.

    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    Ok, try install this plugin from github (https://github.com/piatkowski/wckalkulator/tree/1.4.6). I’ve added is_selected function, example usage: if is_selected(10, {multi_cb}) may be true or false.

    Please give me feedback before I update plugin in WP.org repository.

    Thread Starter castria

    (@castria)

    Ok, I installed the github version.

    The add-on price calculation is as follows ({aps} is multi checkbox, ap1 is the number field that appears when the first checkbox is checked):

    if is_selected(1,{aps}) add {ap1} * 100

    I get the following error message on the product page:

    “Total Arguments must be separated by a comma. Unexpected token “punctuation” of value “.” (“punctuation” expected with value “,”) around position 14 for expression is_selected(1.aps).”

    • This reply was modified 2 years, 4 months ago by castria.
    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    My mistake, should be is_selected({field}; value) and in your case this is is_selected({aps}; 1). Arguments are separated by semicolon, because numbers can be written as 1.23 or 1,23 (we use comma in Poland).

    Thread Starter castria

    (@castria)

    Ah that makes sense. So functionally that is working now. The only issue i’m still seeing is that if nothing is selected in the multicheckbox, i get the error message

    “Total Variable “aps” is not valid around position 13 for expression is_selected(aps, 1).”

    As soon as at least one is checked the error message goes away and it works as intended.

    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    Please give me screen shot of config. Do you use ; to separate arguments ? I tested it and if no option is selected then aps will be empty array(). This error shoud not occur.

    You can also check file src/FieldsetProduct.php lines 349 to 352, should be:

    /* Set Default values if the field is not in POST data */
    if($this->field($name)['type'] === 'checkboxgroup') {
        $filtered_post[$name] = array();
    }

    I can’t find bug on my local dev env.

    Thread Starter castria

    (@castria)

    Yes, I used a semicolon. I’ve double checked the file you mentioned and it shows exactly as you wrote.

    Here is a gallery showing my configs and how the product page shows when nothing is checked vs when something is checked.

    View post on imgur.com

    Plugin Author Krzysztof Pi?tkowski

    (@wckalkulator)

    Ok, I found that issue was when multicheckbox was the only field.
    Try this updated plugin: https://github.com/piatkowski/wckalkulator/releases/tag/1.4.6

    You should not check number fields as required, because it does not pass the validation test. I plan to change behaviour of “required” option to be: 1. always require, 2. require when visible, 3. not required

    At this moment you can set multi checkbox as required instead of number fields.

    Thread Starter castria

    (@castria)

    That works perfectly now. Thanks so much for your efforts! I’ll send a review and a donation your way by today/tomorrow.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Conditional visibility not working with checkboxes’ is closed to new replies.