Closed ogabrielsantos closed 11 years ago
Model settings
'Uploader.FileValidation' => array(
'imagem' => array(
'required' => array(
'value' => false
)
)
)
beforeValidate (at line 245) defined validations:
debug($this->_validations); // Line 322 my code
/**
array(
'imagem' => array(
'required' => array(
'rule' => array(
(int) 0 => 'required'
)
)
)
)
)
*/
Do you get warnings? I was under the assumption that Cake merges in array defaults for the built-in values. If not, then I would have to add an index check.
I get "Undefined index: allowEmpty [APP/Plugin/Uploader/Model/Behavior/FileValidationBehavior.php, line 354]"
It seems that from line 300 to 311 the default settings merge are lost.
2013/11/1 Miles Johnson notifications@github.com
Do you get warnings? I was under the assumption that Cake merges in array defaults for the built-in values. If not, then I would have to add an index check.
— Reply to this email directly or view it on GitHubhttps://github.com/milesj/uploader/issues/154#issuecomment-27582571
Because my model have a required
rule, model's settings replace validation settings at merge from line 310. I think you should verify index existence at line 354.
Thanks for the report, will look into.
I can't seem to reproduce this error. When I add required = false
I get the following debug output.
array(
'required' => array(
'rule' => array(
(int) 0 => 'required',
(int) 1 => false
),
'message' => 'This file is required',
'on' => 'create',
'allowEmpty' => true
)
)
What does the rest of your model look like?
public $actsAs = array(
'Uploader.FileValidation' => array(
'image' => array(
'required' => array(
'value' => false
)
)
),
);
[...]
public $validate = array(
[...]
'image' => array(
'required' => array(
'rule' => array('required'),
'message' => 'This file is required',
'on' => 'create'
)
)
);
You shouldn't be setting the regular validation rules if you are setting FileValidation rules. Remove the $validate
ones.
FileValidation's rules does not implements 'on' => 'create/update', So I need to create model's required rule to merge 'on' with FileValidation's required rule.
2013/11/2 Miles Johnson notifications@github.com
You shouldn't be setting the regular validation rules if you are setting FileValidation rules. Remove the $validate ones.
— Reply to this email directly or view it on GitHubhttps://github.com/milesj/uploader/issues/154#issuecomment-27631979 .
Atte, Gabriel Santos - gabriel@mais.gs gabriel@mais.gs
FileValidation should support on/allowEmpty/and any other rule as well. If it is not working, that is a bug.
So, I think it is not working as expected. Try to edit a entry with follow rules. Here it works as expected for create but fail with update, saying that field is required.
'Uploader.FileValidation' => array(
'image' => array(
'required' => array(
'value' => true,
'message' => 'Select a image',
'on' => 'create',
'allowEmpty' => false
)
)
)
I just tested with those exact settings and ran into no problems. It would only require a file during creation, not uploading.
Assuming file
/Model/Behavior/FileValidationBehavior.php
(https://github.com/milesj/uploader/blob/master/Model/Behavior/FileValidationBehavior.php#L354). Should the index existence (at line 354) be done?I can't see a merge with this setting (at line 95 or somewhere).