rapyd-laravel icon indicating copy to clipboard operation
rapyd-laravel copied to clipboard

Required rule on files doesn't work

Open aperezlillo opened this issue 9 years ago • 2 comments

$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.

aperezlillo avatar Jan 07 '16 11:01 aperezlillo

I know this is old issue, but the same problem occured to me. This is what I did:

  1. 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;
    }
  1. Added additional hidden field to src/DataForm/Field/Image.php. Line 140
if ($this->old_value != "") {
                    $output .= '<div class="clearfix">';
                    $output .= $this->thumb()." &nbsp;".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>';
                }
  1. 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.

seriousTom avatar Aug 18 '17 12:08 seriousTom

Known issue, extend the class and use the subclass.

tacone avatar Aug 30 '17 20:08 tacone