Allow null for drop down values

QuestionsAllow null for drop down values

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;

2 Answers
Abu Ghufran answered 7 years ago

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);

Abu answered 6 years ago

For select2, you must specify some placeholder text. e.g. ‘-‘
$col[“editoptions”] = array(“value”=>”:-;”.$str);

Your Answer

0 + 19 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?