sleeping-owl / admin

Administrative interface builder for Laravel
http://sleeping-owl.github.io/
MIT License
504 stars 259 forks source link

formItem::image->required() problem #240

Closed macedodebrito closed 9 years ago

macedodebrito commented 9 years ago

Hello!

im getting a problem here:

my form have this configuration:

->form(function () { FormItem::ckeditor('text', 'Body')->required(); FormItem::image('image', 'Image')->required(); FormItem::text('description', 'Description')->required()->attributes(['style' => 'width: 300px']); });

The problem is:

IF i dont use image()->required(), and SAVE, i will lose my image. IF i use ->required(), validation isnt recognizing that ONE image is already setted (the thumb one), and give me a validation error "image is required".

How can i fix this?

I'm using LARAVEL 4.

thanks,

macedodebrito commented 9 years ago

ok i got it.

you can "fix/rule" it with:

public function getValidationRules()
{
    if ((Input::get('imageConfirmDelete')) && (Input::file('image')==null)) {
        return [ 'image' => 'required' ];
    }
    else {          
        return [];
    }
}