FileInput Update "validation error'

Hi All,

When using Kartik’s FileInput widget with an ActiveForm I can upload the file when “creating” the record. When I then go back in to Update the record the javascript validation says the field is empty (even though $model->picture_url has a valid url)

How do I set the inital value of the field? I thought this would be done automatically with an activeform?!

I tried using:

$form->field($model, 'picture_url')->widget(FileInput::classname(), [


                                'options' => 

But that did not work either.

$form->field($model, 'picture_url')->widget(FileInput::classname(), [

                                'options' => [

                                    'accept' => 'image/*',

                                    'multiple' => false,


                                'pluginOptions' => [

                                    'initialPreview' => $model->picture_url?Html::img($model->picture_url):'',

                                    'showPreview' => true,

                                    'showCaption' => true,

                                    'showRemove' => true,

                                    'showUpload' => false,

                                    'browseLabel' => '',

                                    'removeLabel' => '',

                                    'previewSettings' => [

                                        'image' => ['width'=> "90%", 'height'=> "auto"],



                                        'image'=> "<div class='custom-file-preview' id='{previewId}' data-fileindex='{fileindex}'>\n".

                                                    "<img src='{data}' class='' style='margin:auto' title='{caption}' alt='{caption}'>\n".


                                        'generic'=> "<div class='custom-file-preview' id='{previewId}' data-fileindex='{fileindex}'>\n".





                                        'preview' => "<div class='file-preview {class}'>\n" .

                                        "    <div class='{dropClass}'>\n" .

                                        "    <div class='file-preview-thumbnails'>\n" .

                                        "    </div>\n" .

                                        "    <div class='clearfix'></div>" .

                                        "    <div class='file-preview-status text-center text-success'></div>\n" .

                                        "    <div class='kv-fileinput-error'></div>\n" .

                                        "    </div>\n" .





Thanks, I have literally been staring at this for 3 hours now :D

How is picture_url getting a value? Generally file input fields are defined as public properties in the model as it is just a temporary place to store the file upload object until the file is uploaded.

So how does your picture_url have a value? If you have echo out, $model->picture_url in the view does it show the URL?

Picture_url gets changed into a relative path in the controller. So to answer your question yes it does echo the path. The problem appears to be with the widget not accepting the $model->picture_url as a valid input (perhaps because it is not a file and is a string)

But the validation error is stating it is blank / empty, yes?