rapyd-laravel
rapyd-laravel copied to clipboard
Required rule on files doesn't work
$edit->add('photo', 'Photo', 'image')->rule('required');
When I add required rule on an image, the validation don't works. It does not show the error message on the form.
I know this is old issue, but the same problem occured to me. This is what I did:
- Commented if statement in src/DataForm/Field/File.php. It is somewhere in 47 line
public function rule($rule)
{
//we should consider rules only on upload
// if (Input::hasFile($this->name)) {
parent::rule($rule);
// }
return $this;
}
- Added additional hidden field to src/DataForm/Field/Image.php. Line 140
if ($this->old_value != "") {
$output .= '<div class="clearfix">';
$output .= $this->thumb()." ".link_to($this->web_path.$this->value, $this->value, array('target'=>'_blank'))."<br />\n";
$output .= Form::checkbox($this->name.'_remove', 1, (bool) Input::get($this->name.'_remove'))." ".trans('rapyd::rapyd.delete')." <br/>\n";
$output .= Form::hidden($this->name.'_old', $this->value)." "; //new hidden old image field
$output .= '</div>';
}
- And then I validated like this:
$edit->add('photo', 'Photo', 'image')->rule('required_if:photo_remove,1|required_if:photo_old,""|image')
Hope it helps.
Known issue, extend the class and use the subclass.