KoolReport's Forum

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

Default value "null" in select input field results in empty string #282

Open Michael Wenleder opened this topic on on May 14, 2018 - 1 comments

Michael Wenleder commented on May 14, 2018

Hi team,

if I define a default option in a select input element with a value of NULL,

var_dump($this->params);

results in an empty string instead of NULL value

array(1) { ["mandantid"]=> string(0) "" }

Code:

Select::create(array(
    "name"=>"mandantSelector",
    "dataStore"=>$this->dataStore("mandant"),
    "defaultOption"=>array("all"=>null),
    "dataBind"=>array(
     "text"=>"mandantname",
    "value"=>"mandantid",
),

This seems like a bug to me. I need to use it in a Select Box if the user wants to select all records without filtering to the parameter. You use this in your example "CustomerSelection.view.php".

Kind regards

KoolReport commented on May 15, 2018

Actually it is not really a bug, it is just a known issue. When the option value is null, the normal <select> in html will render like this <option value=""></option>, there is no null value for select. When the form is posted back to server, you will get the empty string value. But you can force it to be NULL if you want:

if(isset($this->params["mandantid"]) && $this->params["mandantid"]=="")
{
    $this->params["mandantid"] = null;
}

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
bug

Inputs