]> git.andy128k.dev Git - ipf.git/commitdiff
cleanup field and widget base classes
authorAndrey Kutejko <andy128k@gmail.com>
Wed, 3 Sep 2014 18:46:54 +0000 (21:46 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Wed, 3 Sep 2014 18:46:54 +0000 (21:46 +0300)
ipf/form/field.php
ipf/form/field/choice.php
ipf/form/field/multiplechoice.php
ipf/form/form.php
ipf/form/widget.php
ipf/form/widget/input.php

index 741c1edd9ebf422014854a8f737325f74843ef81..c2bb3f508aad1dde364dbb07cedc2f1190ee8dec 100644 (file)
@@ -6,8 +6,6 @@ class IPF_Form_Field
     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())
index 75a1490bd88c90e146a3f42e097068d674cd6d68..368caf069e617dd43131dd90512d2eee2bcb8912 100644 (file)
@@ -3,18 +3,7 @@
 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)
     {
@@ -29,10 +18,16 @@ class IPF_Form_Field_Choice extends IPF_Form_Field
 
     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);
+    }
 }
 
index d4900e9d1f756301cfec50f06dffe9a65bc8a4dd..98af7c9ba4727933a5fe27cde99fd362d7558b9d 100644 (file)
@@ -8,7 +8,7 @@ class IPF_Form_Field_MultipleChoice extends IPF_Form_Field_Choice
     {
         foreach ($value as $v) {
             $find = false;
-            foreach ($this->_choices as $name => $val) {
+            foreach ($this->choices as $name => $val) {
                 if ($v==$val) {
                     $find = true;
                     break;
index 9fab7b80cabee0eea4694c615a9ff084bb4638ca..a79e6c5db6551fe2e1f552e12d2913911f6e9287 100644 (file)
@@ -20,12 +20,13 @@ abstract class IPF_Form implements Iterator
 
     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());
index 718a0ca96dc54d1213bad3cd8b84c8ad9b30b002..e561d6187edbd4a513d93651564049382aca7168 100644 (file)
@@ -2,9 +2,8 @@
 
 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())
index f3a8ee5eb7e362a93dac4fd7e60f9f7c926c3fa5..ae2a960260a46bfaecbec873338c5a7949fb20c9 100644 (file)
@@ -4,6 +4,8 @@ use \PFF\HtmlBuilder\Tag as Tag;
 
 class IPF_Form_Widget_Input extends IPF_Form_Widget
 {
+    public $input_type = '';
+
     public function render($name, $value, $extra_attrs=array())
     {
         $tag = Tag::input()