M
M
Maxim Timofeev2015-09-27 15:43:44
Yii
Maxim Timofeev, 2015-09-27 15:43:44

How to make kartik fileInput required?

I use the download widget:
https://github.com/kartik-v/yii2-widget-fileinput
My brain is already boiling. I can't figure out how to make it a required field. I use activeForm with ajax validation.
Here is the view:

$form->field($forma,'userimg')->widget(FileInput::classname(),[
                            'options' => ['accept' => 'image/*'],
                            'pluginOptions' => [
                                'allowedFileExtensions'=>['jpg', 'gif', 'png', 'bmp'],
                                'previewFileType' => 'image',
                                'showRemove' => false,
                                'showUpload' => false,
                                'browseClass' => 'btn btn-primary btn-block',
                                'browseIcon' => '<i class="glyphicon glyphicon-camera"></i> ',
                                'browseLabel' =>  Yii::t('knopki', 'upload'),
                                'overwriteInitial'=>false,
                            ]])

here is the validation:
['userimg', 'image', 'extensions' => 'png,jpg,jpeg', 'skipOnEmpty' => false, 'maxSize'=>5000000, 'minSize'=>100000, 'uploadRequired'=>Yii::t('order', 'noImage')],

It turns out if 'skipOnEmpty' => false - then there is always an error that there is no photo. And if true, then, accordingly, the field is optional (but it should).
With sambit there is $_files and everything loads fine, but 'userimg' is empty.
How to solve the problem? Maybe the widget is not configured properly? Or is it possible to somehow check the presence of $_FILE in the model in the rules? But with ajax validation, it is not passed. I've been wandering around in circles for 4 hours now. I will be glad to any ideas, advice, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IvanSenishin, 2015-09-27
@IvanSenishin

Most likely an error in the method of loading pictures. Can you provide a more detailed example?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question