Created
May 20, 2010 22:36
-
-
Save bshaffer/408209 to your computer and use it in GitHub Desktop.
handy makeReadOnly() function to put in BaseForm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class BaseForm extends sfFormSymfony | |
{ | |
public function makeReadOnly($field = null) | |
{ | |
if ($field instanceof sfWidget) | |
{ | |
$field->setAttribute('disabled', 'disabled'); | |
if ($field instanceof sfWidgetFormSchemaDecorator) | |
{ | |
foreach ($field->getFields() as $key => $childWidget) | |
{ | |
$this->makeReadOnly($childWidget); | |
} | |
} | |
} | |
else | |
{ | |
if ($field === null) | |
{ | |
$field = array_keys($this->widgetSchema->getFields()); | |
} | |
foreach ((array) $field as $name) | |
{ | |
$this->makeReadOnly($this->widgetSchema[$name]); | |
unset($this->validatorSchema[$name]); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment