-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] [Phalcon 1.3.3] [PHP 5.4+] bug in populating (setDefault) for Select element #2921
Comments
Maybe this is a bug |
I've tested many different conditions and I'm sure this is a bug. |
This is fixed in 2.0.3 |
multiple select in 2.0.3,have "PHP Notice: Array to string conversion" |
@hanfeng2000 Could you please provide a script to reproduce the issue? |
FirmsForm.php: $categories = new Select('categories', Constants::$FirmCategories, [
'id' => 'categories',
'name' => 'categories[]',
'multiple' => true,
'placeholder' => 'Multiple Select'
]);
$categories->setLabel('<i class="fa fa-star-o red"></i> Categories);
$this->add($categories); firms.volt: <div class="form-group">
{{ form.label("categories",['class': 'col-sm-3 control-label no-padding-right']) }}
<div class="col-sm-4">
{{ form.render("categories",['class': 'form-control select2']) }}
</div>
</div> FirmsModel.php: public function afterFetch()
{
$this->categories = explode(',', $this->categories);
$this->categories = array_combine($this->categories, $this->categories);
$this->introduction = htmlspecialchars($this->introduction);
} FirmsController.php: if (!$this->request->isPost()) {
$firm = Firms::findFirst(.....);
if (!$firm) {
return $this->response->redirect('/firms/index');
}
//var_dump($firm->categories);
$this->view->form = new FirmsForm($firm);
return;
} phalcon/tag/selec.zip (corrected) /**
* Generate the OPTION tags based on an array
*
* @param array data
* @param mixed value
* @param string closeOption
*/
private static function _optionsFromArray(data, value, closeOption)
{
var strValue, strOptionValue, code, optionValue, optionText, escaped;
let code = "";
for optionValue, optionText in data {
let escaped = htmlspecialchars(optionValue);
if typeof optionText == "array" {
let code .= "\t<optgroup label=\"" . escaped . "\">" . PHP_EOL . self::_optionsFromArray(optionText, value, closeOption) . "\t</optgroup>" . PHP_EOL;
} else {
if typeof value == "array" {
if in_array(optionValue, value) {
let code .= "\t<option selected=\"selected\" value=\"" . escaped . "\">" . optionText . closeOption;
} else {
let code .= "\t<option value=\"" . escaped . "\">" . optionText . closeOption;
}
} else {
let strOptionValue = (string) optionValue,
strValue = (string) value;
if strOptionValue === strValue {
let code .= "\t<option selected=\"selected\" value=\"" . escaped . "\">" . optionText . closeOption;
} else {
let code .= "\t<option value=\"" . escaped . "\">" . optionText . closeOption;
}
}
}
}
return code;
} |
@hanfeng2000 Could you please create a new issue? Thanks |
Sorry! My English is poor. |
But the option with 0 value selected as default!!!
$form->render('status') output:
I've tried many conditions but it seems that if we have an option with 0 value like my Disable option setting default value for Select element didn't works.
I removed 0 => Disable option from my values array and everything works correctly. like below:
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: