Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5963f57

Browse files
committed
fixes new fields
1 parent 375f5a9 commit 5963f57

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

lib/form/mmReadOnlyBaseForm.class.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,17 @@ private function _handleReadOnlyField($fieldName)
7171
if($this->getWidgetSchema()->offsetExists($fieldName))
7272
{
7373
$this->_setWidgetReadOnly($fieldName);
74-
try {
75-
$this->validatorSchema[$fieldName] = new mmValidatorReadOnly(array(
76-
'value' => $this->getObject()->$fieldName,
77-
'is_new' => $this->getObject()->isNew(),
78-
));
79-
} catch(Doctrine_Record_UnknownPropertyException $e) {
80-
//It's a "virtual" field. No need to validate it since it's not going to be saved in db
81-
} catch(Exception $e) {
82-
//throw new Exception(__FILE__.':'.__LINE__.' encountered an exception: ' . $e->getMessage());
74+
if($this instanceof sfFormDoctrine && !$this->getObject()->isNew())
75+
{
76+
$value = $this->getObject()->$fieldName;
77+
}
78+
else
79+
{
80+
$value = $this->getValue($fieldName);
8381
}
82+
$this->validatorSchema[$fieldName] = new mmValidatorReadOnly(array(
83+
'widget' => $this->validatorSchema[$fieldName]
84+
));
8485
}
8586
}
8687

@@ -178,7 +179,7 @@ private function _setWidgetReadOnly($fieldName)
178179
}
179180
elseif($this->widgetSchema[$fieldName] instanceof sfWidgetFormDate)
180181
{
181-
$this->widgetSchema[$fieldName] = new mmWidgetFormDateReadOnly();
182+
$this->widgetSchema[$fieldName] = new mmWidgetFormDateReadOnly($this->widgetSchema[$fieldName]->getOptions(), $this->widgetSchema[$fieldName]->getAttributes());
182183
}
183184
else
184185
{
@@ -204,7 +205,6 @@ public function setReadOnly(array $fields = array())
204205
}
205206
}
206207

207-
//TODO: Also set embedded forms read-only
208208
foreach($this->getEmbeddedForms() as $f)
209209
{
210210
$f->setReadOnly();

lib/validator/mmValidatorReadOnly.class.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class mmValidatorReadOnly extends sfValidatorBase
1818
*/
1919
protected function configure($options = array(), $messages = array())
2020
{
21-
$this->addRequiredOption('value');
22-
$this->addRequiredOption('is_new');
21+
$this->addRequiredOption('widget');
2322
$this->setOption('required', false);
2423
}
2524

@@ -28,6 +27,6 @@ protected function configure($options = array(), $messages = array())
2827
*/
2928
protected function doClean($value)
3029
{
31-
return $this->getOption('is_new') ? $value : $this->getOption('value');
30+
return $this->getOption('widget')->getDefault();
3231
}
33-
}
32+
}

0 commit comments

Comments
 (0)