From: avl Date: Wed, 20 Aug 2008 12:42:31 +0000 (+0300) Subject: db form fields X-Git-Tag: 0.5~526 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=1316ad43d66a78820df9ec311e454a094a1dc3b1;p=ipf.git db form fields --- diff --git a/ipf/form/db/decimal.php b/ipf/form/db/decimal.php new file mode 100644 index 0000000..45d6f3c --- /dev/null +++ b/ipf/form/db/decimal.php @@ -0,0 +1,8 @@ +'width:40px;'); + return parent::formField($def, $form_field); + } +} \ No newline at end of file diff --git a/ipf/form/db/foreignkey.php b/ipf/form/db/foreignkey.php new file mode 100644 index 0000000..6c10b3b --- /dev/null +++ b/ipf/form/db/foreignkey.php @@ -0,0 +1,12 @@ +getTable()->findAll(); + $def['model'] = $gmodel; + $def['required'] = true; + return parent::formField($def, $form_field); + } +} diff --git a/ipf/form/field/choice.php b/ipf/form/field/choice.php new file mode 100644 index 0000000..a96babe --- /dev/null +++ b/ipf/form/field/choice.php @@ -0,0 +1,36 @@ +setChoices($params['choices']); + } + + public function clean($value){ + parent::clean($value); + if (in_array($value, $this->empty_values)) { + return ''; + } + if (!$this->validValue($value)) + throw new IPF_Exception_Form(__('Invalid choice')); + return $value; + } + + public function setChoices($choices){ + $this->_choices = $choices; + $this->widget->choices = $choices; + } + + public function validValue($value){ + foreach($this->_choices as $name=>$val) + if ($value==$val) + return true; + return false; + } +} + diff --git a/ipf/form/field/modelchoice.php b/ipf/form/field/modelchoice.php new file mode 100644 index 0000000..1ce1ce5 --- /dev/null +++ b/ipf/form/field/modelchoice.php @@ -0,0 +1,30 @@ +model = $params['model']; + if (isset($params['queryset'])){ + $choices = array('--------'=>''); + foreach ($params['queryset'] as $item) { + $choices[(string)$item] = $item->id; + } + $this->setChoices($choices); + } + } + + public function clean($value){ + parent::clean($value); + if (in_array($value, $this->empty_values)) { + return null; + } + //print_r($this->model); + //print $value; + //$this->model->get($value); + $o = $this->model->getTable()->find($value); + return $o; + } +}