model code :- [['thumbnail_image'], 'required', 'message' => 'Please upload an image.'],
form code :-
$form->field($model, 'thumbnail_image')->fileInput(['accept' => 'image/*', 'onchange' => 'readURL(this)'])->label('Thumbnail Image', ['class' => 'control-label thumbnail-image-class'])
File input forces uploading
file with every update. even thumb image value available but it gives error to thumb image is required.
-
Thanks for posting in our issue tracker.
In order to properly assist you, we need additional information:
Thanks!
_This is an automated comment, triggered by adding the label status:need more info._
when I create a new record or change the attribute in update it works correctly. However when I update the record without changing the file attribute I get a javascript error 'thumb image is required' despite the file is already saved and I don't want to update it
Please provide code and steps to reproduce it starting with clean basic app. Thanks.
You can use the when and whenClient options.
[['attribute'], 'required', 'when' => function($model) {
return $model->isNewRecord;
}, 'whenClient' => '() => { return !/\?id=\d+/i.test(document.location.href); }' ],
For server side we can check if the record is new $model->isNewRecord.
Client side depends on how you track records, the example above will check the url for an id query string, if one doesn't exist the rule applies.
Yes its work,
thank you so much.