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(), [
'value'=>$model->picture_url,
'options' =>
But that did not work either.
$form->field($model, 'picture_url')->widget(FileInput::classname(), [
'options' => [
'accept' => 'image/*',
'multiple' => false,
],//filecleared
'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"],
],
'previewTemplates'=>[
'image'=> "<div class='custom-file-preview' id='{previewId}' data-fileindex='{fileindex}'>\n".
"<img src='{data}' class='' style='margin:auto' title='{caption}' alt='{caption}'>\n".
"</div>\n",
'generic'=> "<div class='custom-file-preview' id='{previewId}' data-fileindex='{fileindex}'>\n".
"{content}".
"</div>\n"
],
'layoutTemplates'=>[
'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" .
"</div>"
]
]
])->label(false)
Thanks, I have literally been staring at this for 3 hours now