1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

Radiobutton element Yes - No

Discussion in 'Community' started by lpro87, Aug 1, 2022.

  1. lpro87

    lpro87 New Member

    Level: Community
    Hello,
    Help solve the problem.
    There are three radio button elements where the answers are Yes or No.
    And there is a fourth element of the radio button, where the answer should become Yes, provided that the other three elements with the answer Yes. And if at least one answer is No, then the fourth element should become No.

    In JavaScript, I can do it individually for each of the 3 elements.

    var rbVal = this.form.formElements.get('Form___element1').getValue();
    if (rbVal == '1') {
    this.form.formElements.get('Form___element4').update('1');
    }
    else if (rbVal == '2') {
    this.form.formElements.get('Form___element4').update('2');
    }
     

    Attached Files:

    Last edited: Aug 1, 2022
  2. lousyfool

    lousyfool Well-Known Member

    Level: Community
    Regarding the 4th element, is the user allowed to "override" the pre-selection? In other words, if the 4th element ends up being either Yes or No, can the user still change it to No or Yes, respectively?
    If not (which would seem to make sense to me), I'd say it'd be much easier to make the 4th a (hidden) calc element...
     
  3. lpro87

    lpro87 New Member

    Level: Community
    Yes, the user should not change the fourth element.

    It can also be done with the Calc element. It will only answer Yes or No
     
  4. lousyfool

    lousyfool Well-Known Member

    Level: Community
    Well, then why give him a radio button? As suggested, instead make it a (hidden) calc element where you set the value with a PHP condition depending on 1st-3rd elements?
     
  5. lpro87

    lpro87 New Member

    Level: Community
    Thank you.

    $num1 = '{Form___element1_raw}';
    $num2 = '{Form___element1_raw}';
    $num3 = '{Form___element1_raw}';

    $array = compact("num1", "num2", "num3");
    $countValues = array_count_values($array);
    if($countValues[1] == count($array)){
    echo "yes";
    }
    else{
    echo "no";
    }
     
    Last edited: Aug 1, 2022
  6. lousyfool

    lousyfool Well-Known Member

    Level: Community
    Code (Text):

    $num1 = '{Form___element1_raw}';
    $num2 = '{Form___element1_raw}';
    $num3 = '{Form___element1_raw}';
    if ($num1 == '1' && $num2 == '1' && $num3 == '1') {
        return 'Yes';
    } else {
        return 'No';
    }
     
     
    lpro87 likes this.

Share This Page