--- /dev/null
+<?php
+
+class IPF_Form_DB_Decimal extends IPF_Form_DB{
+ function formField($def, $form_field='IPF_Form_Field_Float'){
+ $def['widget_attrs'] = array('style'=>'width:40px;');
+ return parent::formField($def, $form_field);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class IPF_Form_DB_Foreignkey extends IPF_Form_DB
+{
+ function formField($def, $form_field='IPF_Form_Field_ModelChoice'){
+ $gmodel = new $def['model']();
+ $def['queryset'] = $gmodel->getTable()->findAll();
+ $def['model'] = $gmodel;
+ $def['required'] = true;
+ return parent::formField($def, $form_field);
+ }
+}
--- /dev/null
+<?php
+
+class IPF_Form_Field_Choice extends IPF_Form_Field{
+ public $widget = 'IPF_Form_Widget_SelectInput';
+ protected $_choices = array();
+
+ function __construct($params=array())
+ {
+ parent::__construct($params);
+ if (isset($params['choices']))
+ $this->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;
+ }
+}
+
--- /dev/null
+<?php
+
+class IPF_Form_Field_ModelChoice extends IPF_Form_Field_Choice{
+
+ protected $_model;
+
+ function __construct($params=array()){
+ parent::__construct($params);
+ $this->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;
+ }
+}