Add a new global method getDropdownOptions() for specifying dropdown values

Dropdown overrides now supply the key value and form field name where appropriate.
This commit is contained in:
Sam Georges 2014-05-31 10:40:11 +10:00
parent 435b6d30f9
commit 3f767774c4
1 changed files with 11 additions and 8 deletions

View File

@ -357,6 +357,11 @@ class Form extends WidgetBase
$field->arrayName = $this->arrayName;
$field->idPrefix = $this->getId();
/*
* Set field value
*/
$field->value = $this->getFieldValue($field);
/*
* Simple widget field, only widget type is supplied
*/
@ -416,11 +421,6 @@ class Form extends WidgetBase
if (array_key_exists('disabled', $config)) $field->disabled = $config['disabled'];
if (array_key_exists('stretch', $config)) $field->stretch = $config['stretch'];
/*
* Set field value
*/
$field->value = $this->getFieldValue($field);
return $field;
}
@ -595,16 +595,19 @@ class Form extends WidgetBase
{
if (!$fieldOptions) {
$methodName = 'get'.studly_case($field->columnName).'Options';
if (!method_exists($this->model, $methodName))
if (!method_exists($this->model, $methodName) && !method_exists($this->model, 'getDropdownOptions'))
throw new ApplicationException(Lang::get('backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$methodName, 'field'=>$field->columnName]));
$fieldOptions = $this->model->$methodName();
if (method_exists($this->model, $methodName))
$fieldOptions = $this->model->$methodName($field->value);
$fieldOptions = $this->model->getDropdownOptions($field->columnName, $field->value);
}
else if (is_string($fieldOptions)) {
if (!method_exists($this->model, $fieldOptions))
throw new ApplicationException(Lang::get('backend::lang.field.options_method_not_exists', ['model'=>get_class($this->model), 'method'=>$fieldOptions, 'field'=>$field->columnName]));
$fieldOptions = $this->model->$fieldOptions();
$fieldOptions = $this->model->$fieldOptions($field->value, $field->columnName);
}
return $fieldOptions;