0
我有這樣的模式:修改嵌入表單字段的驗證
propel:
autor:
id: ~
nombre: { type: varchar, size: 255, required: true }
libro:
id: ~
autor_id: { type: integer, size: 11, foreignTable: autor,
foreignReference: id}
titulo: { type: varchar, size: 255 }
paginas: { type: varchar, size: 255, required: true }
這種形式類:
class AutorForm extends BaseAutorForm
{
public function configure()
{
$this->embedRelation('Libro');
}
public function foo()
{
$this->validatorSchema['Libro']['newLibro1']['paginas'] = new
sfValidatorPass();
return $this;
}
}
我調用foo()綁定(後)(內processForm ())。
提交Auto-Libro表單後,如果我沒有在第一個嵌入表單(Libro)的 字段'paginas'中插入任何內容,它將顯示 「必需的」。
但是..爲什麼如果paginas有驗證程序通過?
編輯:馬特的答案後,這是我的代碼:
var_dump($this->embeddedForms['Libro']->validatorSchema['newLibro1']['paginas']);
$this->embeddedForms['Libro']->validatorSchema['newLibro1']['paginas'] = new sfValidatorPass(array('required' => false));
var_dump($this->embeddedForms['Libro']->validatorSchema['newLibro1']['paginas']);
它打印此:
object(sfValidatorString)[152]
protected 'requiredOptions' =>
array
empty
protected 'defaultMessages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
'max_length' => string '"%value%" is too long (%max_length% characters max).' (length=52)
'min_length' => string '"%value%" is too short (%min_length% characters min).' (length=53)
protected 'defaultOptions' =>
array
'required' => boolean true
'trim' => boolean false
'empty_value' => string '' (length=0)
'max_length' => null
'min_length' => null
protected 'messages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
'max_length' => string '"%value%" is too long (%max_length% characters max).' (length=52)
'min_length' => string '"%value%" is too short (%min_length% characters min).' (length=53)
protected 'options' =>
array
'required' => boolean true
'trim' => boolean false
'empty_value' => string '' (length=0)
'max_length' => int 255
'min_length' => null
object(sfValidatorPass)[196]
protected 'requiredOptions' =>
array
empty
protected 'defaultMessages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
protected 'defaultOptions' =>
array
'required' => boolean true
'trim' => boolean false
'empty_value' => null
protected 'messages' =>
array
'required' => string 'Required.' (length=9)
'invalid' => string 'Invalid.' (length=8)
protected 'options' =>
array
'required' => boolean false <<<<<<<<<<<< FALSE <<<<<<<<<<<<<<<<<<
'trim' => boolean false
'empty_value' => null
的問題仍然是相同的:當我嘗試提交表單,該領域'paginas'仍然是必需的。爲什麼?
SF 1.4/1.6推進
哈維
謝謝,我寫的行,你說,但它仍然無法正常工作...我有我的編輯問題補充更多的線索。 – ziiweb 2011-04-07 11:40:26
嗯,我不知道。你的表單域在實際提交中如何組織? - 有可能提交的paginas沒有擊中你的validatorPass,而是在BaseAutorForm中擊中默認驗證器? – matt 2011-04-08 16:45:57