Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating resource with attached photos - field is required error #353

Closed
bradykeeling opened this issue Aug 30, 2018 · 9 comments
Closed

Comments

@bradykeeling
Copy link

Nova 1.0.8

When I try to update a resource that has an image previously attached to it, it gives an error saying "field is required."

The update form shows the thumbnail of image, but says "no file selected".

I'm able to access the resource image in my views and the file name is stored in the database, so I'm not sure why I am getting these errors. Am I missing something?

Please see screenshots:

screen shot 2018-08-30 at 11 40 40 am

screen shot 2018-08-30 at 11 42 43 am

screen shot 2018-08-30 at 11 43 36 am

@v1nk0
Copy link

v1nk0 commented Sep 4, 2018

I guess this is nothing browser related.

The input field seems to stay empty when not overwriting the existing file/image/avatar, so for the validation, the "required" rule is not matched.

@StanBarrows
Copy link

@bradykeeling

Did you found a workaround for this problem?

@bradykeeling
Copy link
Author

@StanBarrows Not really... I just disabled the "required" rule until a fix is released.

@fukumori
Copy link

Try use this closure instead 'required' rule:

function ($attribute, $value, $fail) use ($request) {
    $model = $this->resource->find($request->route('resourceId'));
    if (empty($value) && empty($model->$attribute)) {
        $fail(__(':Attribute is required.', ['attribute' => __($attribute)]));
    }
},

@bradykeeling
Copy link
Author

Thanks @lfukumori, I'll give this a go!

Also, what is the purpose of the double underscore "__" before the $attribute variable?

@fukumori
Copy link

The $fail() parameter is a fail message. Something like "Field is required.". The function with double underscore __() is for translate this sentence and attribute.

@caseydwyer
Copy link

Nova 1.1.4 and somewhat related—I'm also getting this error for Image fields that aren't required, but are submitted empty, regardless of previously attached images/files. Also tried adding sometimes to rules; no dice. Example code:

Image::make('Email Image')
  ->rules('mimes:jpeg,jpg,png')
  ->help('Image used in header of all email messages.'),

Image::make('Social Image')
  ->rules('sometimes', 'mimes:jpeg,jpg,png')
  ->help('Image used in social network preview cards.'),

image

@ceejayoz
Copy link

@dwyer14 I opened a new issue for that; it's a separate thing. #1050

@davidhemphill
Copy link
Contributor

I believe this issue should be fixed. Please post a new issue if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants