Blank option in select box

QuestionsBlank option in select box
Mattias Cederlund asked 10 years ago

Hi!
I am making selectboxes which works fine, but i would like to add options that are not available in the table i take it from.

Means, i would like to add one blankd option, and some others. But i dont want to pick them from the db.

This is because i need to select nothing or "" in some cases.

Here is my code:

$col = array();
$col["title"] = "Customer Account Manager";
$col["name"] = "CustomerAccountManagerId";
$col["editable"] = false;
$col["formatter"] = "select";
$col["width"] = "80";
$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 User_Id as k, User_Name as v from user where UserGroup=6");
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array(
"sql"=>"select * from user",
"search_on"=>"User_Id",
"callback" => "fill_form" )
);
//$col["stype"] = "select"; // enable dropdown search
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;

Thanks!
mattias

5 Answers
Abu Ghufran answered 10 years ago

Add ":;" with editoptions.

$col["editoptions"] = array(
"value"=>":;".$str,
….

Mattias Cederlund answered 10 years ago

Amazing – thanks!

If i do this in bulkedit it doesnt work although – can i make an option called "Empty" that inserts "" into the cell, or how to do it?

Abu Ghufran answered 10 years ago

This is currently not supported. I am adding it in todos.

Alec Clarke answered 10 years ago

This is not an answer, but I would 1) like to express that I also would be interested in being able to set the value of a field to "" for bulk edit and 2) I would like to know if there is a way during onchange within editoptions to have a blank value as an option. I have used your method successfully for when the dropdown is first loaded, but during onchange I am limited to the results. I have come up with a workaround, which is to take the sql for the onchange event and do a "UNION (SELECT '' as k, '' as v FROM DUAL)", which adds in the blank value for the dropdown. But it would be cleaner if the grid allowed it.

Abu Ghufran answered 10 years ago

I've added -Empty- option for bulk edit dropdown value.
Emailing you updated lib.

Your Answer

16 + 7 =

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?