2010
02.21
02.21
The symfony forms framework is quite impressive and saves a lot of time in a developpers live!
I’m posting a Widget which handles “readonly” fields. One could use the html attribute “disabled” by setting the attribute property of a widget:
$this->widgetSchema['readonlyfieldname']->setAttribute('disabled', 'disabled');
The problem is that “disabled” elements are ignored when posting the form.
So we need another solution. I came up with a simple WidgetForm which outputs a div tag with the current value and the field itself as a hidden input:
/** * cnWidgetFormInputTextReadonly represents a readonly HTML text input tag. * * @package cn * @subpackage widget * @author Markus Welter * @version SVN: $Id: cnWidgetFormInputTextReadonly.class.php 23810 2010-02-21 19:25:44Z markus $ */ class cnWidgetFormInputTextReadonly extends sfWidgetForm { /** * @param array $options An array of options * @param array $attributes An array of default HTML attributes * * @see sfWidgetForm */ protected function configure($options = array(), $attributes = array()) { parent::configure($options, $attributes); $this->addOption('class'); $this->setOption('class', 'readonlyWidget'); } public function render($name, $value = null, $attributes = array(), $errors = array()) { return ''.$value.''.$this->renderTag('input', array_merge(array('type' => 'hidden', 'name' => $name, 'value' => $value), $attributes)); } }
No Comment.
Add Your Comment