KoolReport's Forum

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

Input - Checkbox #1070

Closed Donald Orban opened this topic on on Aug 30, 2019 - 6 comments

Donald Orban commented on Aug 30, 2019

I have successfully got the Checkbox input to function, but when the post comes back the checkboxs aren't check with the values I have selected, they are all unchecked.

protected function defaultParamValues()
    {
        $case_subtype = CaseModel::select('case_subtype')->groupBy('case_subtype')->get();
        return array(
            "case_subtype" => $case_subtype->toArray()
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "case_subtype" => 'case_subtype'
        );
    }

in the view blade..

CheckBoxList::create(array(
                        "name"=>"case_subtype",
                        "dataStore"=>$data->dataStore("data2"),
                        "dataBind"=>"case_subtype"
                    ));
KoolReport commented on Sep 2, 2019

I have not understood this line of code:

"dataStore"=>$data->dataStore("data2"),

it seems we do not have the $data variable that act like report. Do you set $data = $this; or sth.

Donald Orban commented on Sep 3, 2019

I am using laravel, so when I pass the value to the view, I name the report value $data. I've dug into the code and the part where the checkboxes are generated it searches for the value in the array, but the value is never set. Below is a var dump of the checkbox at the bottom of the init function.

CheckBoxList {#746 ▼
  #dataBind: array:2 [▼
    "value" => "case_subtype"
    "text" => "case_subtype_full"
  ]
  #display: "vertical"
  #defaultOption: null
  #name: "case_subtype"
  #data: array:4 [▼
    0 => array:2 [▼
      "text" => null
      "value" => null
    ]
    1 => array:2 [▼
      "text" => "Complaint"
      "value" => "COMP"
    ]
    2 => array:2 [▼
      "text" => "Incident Report"
      "value" => "IR"
    ]
    3 => array:2 [▼
      "text" => "Mortality"
      "value" => "MRC"
    ]
  ]
  #value: []
  #attributes: array:1 [▶]
  #clientEvents: []
  #params: array:4 [▶]
  #report: WidgetContainer {#750 ▶}
  #assetManager: null
  #language: null
  #languageMap: null
  #dataStore: DataStore {#662 ▶}
  #onReady: null
  #themeBase: null
  #themeCssClass: null
  #withoutLoader: false
}
Donald Orban commented on Sep 3, 2019

When the below line is executed, there is nothing in $this->value. $this->value is null.

<input type="checkbox" aName="<?php echo $this->name; ?>" name="<?php echo $this->name."[]"; ?>" value="<?php echo $value ?>" <?php echo(in_array($value,$this->value))?"checked":""; ?>>
KoolReport commented on Sep 6, 2019

The CheckBoxList should rendered inside the report view file otherwise it may not receive the binding value from report.

Donald Orban commented on Sep 11, 2019

The <input> above is rendered HTML inside the report view. It isn't rendering with $this->value. Below is the code in the view file. When I dump the values as the CheckBoxList class is called there is no value in $this->value; $this->name has the proper data in it. CheckBoxList::create(array(

      "name"=>"case_subtype",
      "dataStore"=>$data->dataStore("data2"),
      "dataBind"=>"case_subtype"

));

Donald Orban commented on Sep 11, 2019

Figured out a work around, I manually get the values from $_POST and assign the "value" parameter to the CheckBoxList like below, if anyone else is having issues.

                                CheckBoxList::create(array(
                                    "name"=>"checkBoxList",
                                    "dataStore"=>$data->dataStore("data2"),
                                    "dataBind"=>array(
                                        "value" =>"case_subtype",
                                        "text"=>"case_subtype_full"
                                    ),
                                    "value"=>$_POST['checkBoxList'],
                                    "attributes"=>array(
                                        "class"=>"form-control"
                                    )
                                ));

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
help needed

Inputs