When a drop down value is not required but is queried from another table…how do I allow no selection?
See my code below. The PuArr2 ALLOWS the user to leave "unassigned" but the second one automatically inserts the first record in the lookup.
$col = array();
$col["title"] = "Stop2";
$col["name"] = "stop2";
$col["dbname"] = "locationTbl2.code"; // this is required as we need to search in name field, not id
$col["width"] = "18";
$col["align"] = "center";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values("select distinct id as k, code as v from locationTbl where active = 1 order by v");
$col["editoptions"] = array("value"=>$str);
$col["show"] = array("view"=>true, "add"=>true, "edit"=>true, "list"=>false);
$col["isnull"] = true;
$col["editrules"] = array("required"=>false);
$cols[] = $col;
$col = array();
$col["title"] = "PuAr2";
$col["name"] = "pu_arrival_reason2";
$col["align"] = "center";
$col["width"] = "19";
$col["editable"] = true; // this column is editable
$col["edittype"] = "select";
$col["editoptions"] = array("value"=>'A1:A1–Missed Delivery;A2:A2–Incorrect Address;');
$col["editrules"] = array("required"=>false); // and is required
$col["show"] = array("view"=>true, "add"=>true, "edit"=>true, "list"=>false);
$col["isnull"] = true;
$cols[] = $col;
Try appending ":;" before dropdown values. It will add null option.
$str = $g->get_dropdown_values("select distinct id as k, code as v from locationTbl where active = 1 order by v");
$col["editoptions"] = array("value"=>":;".$str);