Yii2:Kartik FileInput Widget 设置 id 以捕获事件

Yii2: Kartik FileInput Widget set id to catch events

我尝试为 Kartik FileInput 小部件设置 ID,但它似乎无法设置它。因为我无法在成功上传后捕获文件上传事件。
view.php

echo $form->field($ebook, 'imageFile')->widget(FileInput::classname(), [
    'id'            => 'imageFile',
    'options'       => ['accept' => 'pdf/*'],
    'pluginOptions' => [
        'allowedFileExtensions' => ['pdf'],
        'showPreview'           => false,
        'showUpload'            => true,
        'uploadAsync'           => true,
        'uploadUrl'             => Url::to(['site/upload']),
    ]
]);

catchevent.js

$('#imageFile').on('fileuploaded', function(event, data, previewId, index) {
    var form = data.form, files = data.files, extra = data.extra,
        response = data.response, reader = data.reader;
    console.log('File uploaded triggered');
});

将 id 移动到选项列表中:

echo $form->field($ebook, 'imageFile')->widget(FileInput::classname(), [
    'options'       => ['accept' => 'pdf/*', 'id' => 'imageFile',],
    'pluginOptions' => [
        // ...
    ]
]);

您可以在 docs

中找到它