Closed DominiqueFERET closed 10 years ago
Hey Dominique, this is because of some magic I try to do to detect associative vs. non-associative arrays.
Unfortunately in PHP there is absolutely no way to tell the difference between this:
[
"0" => "Select a format",
"1" => "A4",
"2" => "A3"
];
...and just this (no keys):
[
"Select a format",
"A4",
"A3"
];
Any other numbers would work fine, as long as they are not all in order and starting at 0.
BootForms tries to do you a favor and sets the value
attribute to be the same as the text inside the option tag if it thinks you didn't set any custom keys, so that you don't have to type this:
[
"Select a format" => "Select a format",
"A4" => "A4",
"A3" => "A3"
];
...but maybe it's not worth it. Probably going to just rip out that functionality and force you to set keys if you don't want the array indexes as your values.
You have solved my problem. 0 is not a selection. other values are an id to another table. I was just blocked because I did not understand the reason ... I just have to replace the 0 with a space and then check if the value returned is numeric to be sure that choice was made by the user.
i have tried and this work fine =>
...
$formatlist=array(" " => "Select a format", "1"=>"A4", "2"=>"A3");
...
{{ BootForm::select('Format','format',$formatlist)}}
So, i want to say many thanks for your help and for this great job. best regards,
Dominique
Glad you were able to come up with a solution and glad you are getting some use out of the package. Thanks for the kind words!
This is something that has caused issues for me on multiple occasions.
...but maybe it's not worth it. Probably going to just rip out that functionality and force you to set keys if you don't want the array indexes as your values.
Adding am optional flag to disable functionality would probably be a good compromise.
Nah I'm just gonna rip it out, we'll do it live, fuck it.
Done.
https://github.com/adamwathan/form/commit/9eecb96f9df9d14e3c6aa215c1cad89b15044ebb
Will tag a new version of Form and BootForms soon with this change!
Even improved my score on Scrutinizer
Wins all around!
Hello,
I try to make a select with this code:
and the result is:
instead of
Where is the mistake ? can you help me please ?
Best regards,
Dominique