public $label = '';
public $required = false;
public $help_text = '';
- public $choices = null;
- public $value = ''; /**< Current value of the field. */
protected $empty_values = array('', null, array());
function __construct($params=array())
class IPF_Form_Field_Choice extends IPF_Form_Field
{
public $widget = 'IPF_Form_Widget_SelectInput';
- protected $_choices = array();
-
- function __construct($params=array())
- {
- $this->_choices = \PFF\Arr::pop($params, 'choices', array());
-
- $widget_attrs = \PFF\Arr::pop($params, 'widget_attrs', array());
- $widget_attrs['choices'] = $this->_choices;
- $params['widget_attrs'] = $widget_attrs;
-
- parent::__construct($params);
- }
+ public $choices = array();
public function clean($value)
{
public function validValue($value)
{
- foreach ($this->_choices as $name => $val)
+ foreach ($this->choices as $name => $val)
if ($value == $val)
return true;
return false;
}
+
+ protected function createWidget($args)
+ {
+ $args['choices'] = $this->choices;
+ return parent::createWidget($args);
+ }
}
{
foreach ($value as $v) {
$find = false;
- foreach ($this->_choices as $name => $val) {
+ foreach ($this->choices as $name => $val) {
if ($v==$val) {
$find = true;
break;
function __construct($data=null, $extra=array())
{
+ $this->initFields($extra);
+
if ($data !== null) {
$this->data = $data;
$this->is_bound = true;
}
$this->initial = \PFF\Arr::get($extra, 'initial', array());
- $this->initFields($extra);
}
abstract protected function initFields($extra=array());
abstract class IPF_Form_Widget
{
- public $is_hidden = false;
+ public $is_hidden = false; // renders invisible
public $needs_multipart_form = false;
- public $input_type = '';
public $attrs = array();
public function __construct($attrs=array())
class IPF_Form_Widget_Input extends IPF_Form_Widget
{
+ public $input_type = '';
+
public function render($name, $value, $extra_attrs=array())
{
$tag = Tag::input()