Clear the fileinput in yii2 using pluginEvents

The selected files still appears on fileinput preview after showing the alert “File too Big, please select a file less than 2mb”.

```
 echo '<div style="margin-left: 27px;">';                       
      echo $form->field($model, 'value[]')->widget(FileInput::classname(), [
      'options' => ['multiple' => true, 'accept' => 'jpg/png/jpeg/pdf/doc/docx/xlsx/*'],
      'pluginOptions' => ['allowedFileExtensions' => ['jpg','png','jpeg','pdf', 'doc', 'docx','xlsx'],
       'showUpload' => false,
       'initialPreview' => $getuploadedfile,
       'initialPreviewConfig' => $ImageConfig,
        'overwriteInitial' => false
        ],
       'pluginEvents' => [
          "change" => 'function() { 
              if (this.files.length > 0) { 
                 for (var i = 0; i <= this.files.length - 1; i++) {                          
                   const fsize = this.files.item(i).size; 
                   const file = Math.round((fsize / 1024)); 

                   if (file >= 2048) { 
                       alert("File too Big, please select a file less than 2mb"); 
                       this.value = "";

                    }
                 } 
            } 
          }',
         ]
        ])->label(false);
echo '</div>';
```

I want to clear the fileinput after showing that alert. Please help me. I tried the this.fileinput(“clear”) but not worked.

To clear the file input after the alert, you can try this in your code:

if (file >= 2048) { 
  alert("File too Big, please select a file less than 2mb"); 
  $(this).closest('.file-input').find('.fileinput-remove-button').trigger('click');
}

This code finds the remove button in the file input and clicks it, which should clear the selection. Make sure to adjust the class .file-input to match your file input’s class.