Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/Jonob/Formly/Formly.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ private function loadConfig()
*/
public function setDefaults($defaults = array())
{
$defaults = json_decode(json_encode($defaults), true);

if (count($defaults) > 0)
{
$this->defaults = (object)$defaults;
$this->defaults = $defaults;
}

return $this;
Expand Down Expand Up @@ -488,7 +490,10 @@ private function buildLabel($name, $label = '')
private function calculateValue($name, $default = '', $radioValue = '')
{
$result = '';


//make array named fields to dot notation
$field_name = str_replace(array('[', ']'), array('.', ''), $name);

// First check if there is post data
// This assumes that you are redirecting after failed post
// and that you have flashed the data
Expand All @@ -508,11 +513,11 @@ private function calculateValue($name, $default = '', $radioValue = '')
}

// lastly, check if any defaults have been set for the form as a whole
elseif (isset($this->defaults->$name))
elseif ($value = array_get($this->defaults, $field_name))
{
$result = ($radioValue)
? $this->defaults->$name == $radioValue
: $this->defaults->$name;
? $value == $radioValue
: $value;
}

return $result;
Expand Down Expand Up @@ -695,4 +700,4 @@ public function close()
{
return Form::close();
}
}
}