From 52bc6cd4fb6f7ba3c8be4639ab592ff158684da6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 25 Mar 2013 15:23:59 -0500 Subject: [PATCH] Fix bug with check state in form builder. --- FormBuilder.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/FormBuilder.php b/FormBuilder.php index 6aaadb5..8aff476 100644 --- a/FormBuilder.php +++ b/FormBuilder.php @@ -483,13 +483,28 @@ class FormBuilder { */ protected function checkable($type, $name, $value, $checked, $options) { - if (is_null($checked)) $checked = (bool) $this->getValueAttribute($name, null); + if (is_null($checked)) $checked = $this->getCheckedState($type, $name, $value); if ($checked) $options['checked'] = 'checked'; return $this->input($type, $name, $value, $options); } + /** + * Get the check state for a checkable input. + * + * @param string $type + * @param string $name + * @param mixed $value + * @return void + */ + protected function getCheckedState($type, $name, $value) + { + if ($type == 'checkbox') return (bool) $this->getValueAttribute($name); + + return $this->getValueAttribute($name) == $value; + } + /** * Create a submit button element. * @@ -662,7 +677,7 @@ class FormBuilder { * @param string $value * @return string */ - protected function getValueAttribute($name, $value) + protected function getValueAttribute($name, $value = null) { if ( ! is_null($value)) return $value;