@@ -37,6 +37,8 @@ public function __construct($defaults = array(), $options = array(), $CSRFSecret
3737
3838 $ this ->addCSRFProtection ($ this ->localCSRFSecret );
3939 $ this ->resetFormFields ();
40+
41+ $ this ->_handleReadOnlyFields ();
4042 }
4143
4244 /**
@@ -66,22 +68,25 @@ private function _handleNotVisibleField($fieldName)
6668 * Mark the widgets as readonly &&
6769 * creates a validator if appropriate
6870 */
69- private function _handleReadOnlyField ( $ fieldName )
71+ private function _handleReadOnlyFields ( )
7072 {
71- if ($ this ->getWidgetSchema ()-> offsetExists ( $ fieldName) )
73+ foreach ($ this ->_readOnlyFields as $ fieldName )
7274 {
73- $ this ->_setWidgetReadOnly ($ fieldName );
74- if ($ this instanceof sfFormDoctrine && !$ this ->getObject ()->isNew ())
75- {
76- $ value = $ this ->getObject ()->$ fieldName ;
77- }
78- else
75+ if ($ this ->getWidgetSchema ()->offsetExists ($ fieldName ))
7976 {
80- $ value = $ this ->getValue ($ fieldName );
77+ $ this ->_setWidgetReadOnly ($ fieldName );
78+ if ($ this instanceof sfFormDoctrine)
79+ {
80+ $ value = $ this ->widgetSchema [$ fieldName ]->getDefault () ? $ this ->widgetSchema [$ fieldName ]->getDefault () : $ this ->getObject ()->$ fieldName ;
81+ }
82+ else
83+ {
84+ $ value = $ this ->widgetSchema [$ fieldName ]->getDefault ();
85+ }
86+ $ this ->validatorSchema [$ fieldName ] = new mmValidatorReadOnly (array (
87+ 'value ' => $ value ,
88+ ));
8189 }
82- $ this ->validatorSchema [$ fieldName ] = new mmValidatorReadOnly (array (
83- 'widget ' => $ this ->validatorSchema [$ fieldName ]
84- ));
8590 }
8691 }
8792
@@ -126,7 +131,7 @@ public function addReadOnlyField($fieldName)
126131 {
127132 throw new InvalidArgumentException (__FUNCTION__ . ': Invalid Argument type. Expected String, got ' . gettype ($ fieldName ));
128133 }
129- $ this ->_handleReadOnlyField ( $ fieldName) ;
134+ $ this ->_readOnlyFields [] = $ fieldName ;
130135 }
131136
132137 /**
@@ -139,7 +144,7 @@ public function addReadOnlyFields(array $fields)
139144 {
140145 foreach ($ fields as $ fieldName )
141146 {
142- $ this ->_handleReadOnlyField ( $ fieldName) ;
147+ $ this ->_readOnlyFields [] = $ fieldName ;
143148 }
144149 }
145150
@@ -201,7 +206,7 @@ public function setReadOnly(array $fields = array())
201206 {
202207 foreach ($ this ->widgetSchema ->getFields () as $ fieldName => $ w )
203208 {
204- $ this ->_handleReadOnlyField ( $ fieldName) ;
209+ $ this ->_readOnlyFields [] = $ fieldName ;
205210 }
206211 }
207212
0 commit comments