KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Creating radiolist of yes/no for all items from a datastore. #1680

Open Richb201 opened this topic on on Oct 23, 2020 - 12 comments

Richb201 commented on Oct 23, 2020

I have created a survey that gets populated by a datastore, Here is the code that generates it:

<div class="col-md-6 form-group">
    <strong>Activities - please check off activites performed by you</strong>
    <?php
    CheckBoxList::create(array(
        "name"=>"Please check off Activities performed.",
        "dataStore"=>$this->dataStore("activity"),
        "dataBind"=>""
    ));
    ?>
</div>

and here is the form it creates.

Instead of the checkbox, I'd like to use a radiobutton for each line that says yes no. Can I use a radio button that toggles yes/no for each line? Please show me how I would change the above code.

KoolReport commented on Oct 23, 2020

You can use RadioList instead of CheckBoxList

Richb201 commented on Oct 23, 2020

But that will cause radio buttons where the choices will be between each activity. I need the choice between yes or no for each activity. Do you understand what I am saying?

KoolReport commented on Oct 23, 2020

Please give me a drawing of what you want to be appeared.

Richb201 commented on Oct 23, 2020

here is what I mean. I want the radio choice to be between yes or no. The activities are coming from a datastore.

Richb201 commented on Oct 26, 2020

OK. You asked for an example and I supplied one. Any ideas?

KoolReport commented on Oct 27, 2020

Sorry for my late reply, it will be something like this:

<?php
foreach($this->dataStore("activity") as $i=>$row) {
    echo "<div>";
    echo $row["text"];
    \koolreport\inputs\RadioList::create([
        "name"=>"radio".$i,
        "data"=>[
            "Yes"=>1,
            "No"=>0
        ],
        "display"=>"horizontal"
    ])
    echo "</div>";
}
?>
Richb201 commented on Oct 27, 2020

Thanks. I modified my code. As you can see I have both the "old way" and the code above. Below is the result. The new way had an issue with the def of text.

    <?php
    CheckBoxList::create(array(
        "name"=>"Please check off Activities performed.",
        "dataStore"=>$this->dataStore("activity"),
        "dataBind"=>""
    ));
    ?>
    
    <?php
    foreach($this->dataStore("activity") as $i=>$row) {
        echo "<div>";
        echo $row["text"];
        \koolreport\inputs\RadioList::create([
            "name"=>"radio".$i,
            "data"=>[
                "Yes"=>1,
                "No"=>0
            ],
            "display"=>"horizontal"
        ]);
    echo "</div>";
}
    ?>

KoolReport commented on Oct 27, 2020

I do not know the field in your dataStore, so I put "text" with expection that you will replace with your field. The code I provide is pseudo code to present the idea.

Richb201 commented on Oct 27, 2020

Thanks. That almost worked. See attached. I can't have a default. Also I'd like the yes/no on the same line (horizontal) as the text. see the example Having the default is a big problem since I am making a ratio of yes to no. I created a "n/a" and set it to 0 and that seems to work. Now if I can just get these to be "activity yes o no o n/a o" that would be great.

KoolReport commented on Oct 27, 2020

May I know which version of bootstrap are you using?

KoolReport commented on Oct 27, 2020

May be you try to add following css style to your page:

<style>
.radio-inline {
    display: -webkit-inline-box;
    display: -ms-inline-flexbox;
    display: inline-flex;
    margin-right: 1rem;
}
</style>

Let me know if it works.

Richb201 commented on Oct 27, 2020

That worked well. Is there a way to get them to line up in columns?

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None