Delete buttons in Preview zone after reset are not work

Web Tips Q & ACategory: Krajee Yii2 ExtensionsDelete buttons in Preview zone after reset are not work
Anonymous asked 1 year ago

I use your widget on form in DetailView.It works fine except a one issue:-when I want  to reset a form and restore original images in preview zone they are successfully restored, butDelete button is dead until I add aby other image.My source: resetOptions in DetailView:

'resetOptions'=>['onclick'=>"$('#casestudies-images').fileinput('clear');
$('#casestudies-images').fileinput ('refresh', { 
    initialPreview:[
        '<img src="/resources/image1.png">', 
        '<img src="/resources/image2.png">'
    ],
    initialPreviewConfig: [
        {'url':'/casestudies/delete','key':3},
        {'url':'/casestudies/delete','key':4}
    ] 
});

Corresponding column in DetailView:

'columns' => [ 
	[ 
		'attribute'=>'images[]', 
		'format'=>'raw', 
        'label'=>'', 
        'value'=>$this->render('_images_list', ["model"=>$model]), 
        'type'=>DetailView::INPUT_FILEINPUT, 
        'widgetOptions'=>[ 
            'options'=>['multiple'=>'multiple'],
            'pluginOptions' => [
                'initialPreview'=> $aImages,
                'initialPreviewConfig'=>$aPreviewConfig, 
                'showUpload'=>false, 
                'initialPreviewShowDelete'=>true, 
                'showClose'=>false, 
                'showCaption'=>false, 
                'dropZoneEnabled'=>false, 
                'uploadUrl'=> "/url", 
                'maxFileCount' => 5, 
                'overwriteInitial'=>false, 
                'showRemove'=>false, 
                //'allowedFileExtensions'=>["jpg", "png", "bmp", "jpeg", "gif"], 
                'allowedFileTypes'=>["image"], 
                'maxFileSize'=>1024
            ]
        ]
    ]
],
1 Answers
spt answered 1 year ago

I have found a reason.
It is necessary to reset whole form before resetting a widget.
So, resetOptions code in the DetailsView should looks like:

'resetOptions'=>['onclick'=>"$("#formId").trigger("reset");
$('#casestudies-images').fileinput('clear');
$('#casestudies-images').fileinput ('refresh',  .... ); return false;"

 

Kartik Staff replied 1 year ago

If you are not using ajax mode of the plugin (i.e. using form based submission) – then on resetting the form – the plugin will auto reset the file input and preview.

Login or register to contribute or comment.

Login   Register