Fix form populating with array names
This commit is contained in:
1 parent
fdb891e180
commit
1b09282378
1 file changed
+24
-9
+24
-9
@@ -596,7 +596,7 @@ class FormBuilder {
|
||||
switch ($type)
|
||||
{
|
||||
case 'checkbox':
|
||||
return $this->getCheckboxCheckedState($name, $checked);
|
||||
return $this->getCheckboxCheckedState($name, $value, $checked);
|
||||
|
||||
case 'radio':
|
||||
return $this->getRadioCheckedState($name, $value, $checked);
|
||||
@@ -614,13 +614,17 @@ class FormBuilder {
|
||||
* @param bool $checked
|
||||
* @return bool
|
||||
*/
|
||||
protected function getCheckboxCheckedState($name, $checked)
|
||||
protected function getCheckboxCheckedState($name, $value, $checked)
|
||||
{
|
||||
if ( ! $this->oldInputIsEmpty() and is_null($this->old($name))) return false;
|
||||
|
||||
if ($this->missingOldAndModel($name)) return $checked;
|
||||
|
||||
return (bool) $this->getValueAttribute($name);
|
||||
$valueAttribute = $this->getValueAttribute($name);
|
||||
|
||||
if (is_array($valueAttribute)) return in_array($value, $valueAttribute);
|
||||
|
||||
return (bool) $valueAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -870,14 +874,14 @@ class FormBuilder {
|
||||
{
|
||||
if (is_null($name)) return $value;
|
||||
|
||||
if (isset($this->session) and $this->session->hasOldInput($name))
|
||||
if ( ! is_null($this->old($name)))
|
||||
{
|
||||
return $this->session->getOldInput($name);
|
||||
return $this->old($name);
|
||||
}
|
||||
|
||||
if ( ! is_null($value)) return $value;
|
||||
|
||||
if (isset($this->model) and isset($this->model[$name]))
|
||||
if (isset($this->model))
|
||||
{
|
||||
return $this->getModelValueAttribute($name);
|
||||
}
|
||||
@@ -893,11 +897,11 @@ class FormBuilder {
|
||||
{
|
||||
if (is_object($this->model))
|
||||
{
|
||||
return object_get($this->model, $name);
|
||||
return object_get($this->model, $this->transformKey($name));
|
||||
}
|
||||
elseif (is_array($this->model))
|
||||
{
|
||||
return array_get($this->model, $name);
|
||||
return array_get($this->model, $this->transformKey($name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -911,7 +915,7 @@ class FormBuilder {
|
||||
{
|
||||
if (isset($this->session))
|
||||
{
|
||||
return $this->session->getOldInput($name);
|
||||
return $this->session->getOldInput($this->transformKey($name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,6 +929,17 @@ class FormBuilder {
|
||||
return (isset($this->session) and count($this->session->getOldInput()) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform key from array to dot syntax.
|
||||
*
|
||||
* @param string $key
|
||||
* @return string
|
||||
*/
|
||||
protected function transformKey($key)
|
||||
{
|
||||
return str_replace(array('.', '[]', '[', ']'), array('_', '', '.', ''), $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the session store implementation.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user