我尝试为 Kartik FileInput 小部件设置 id,但它似乎不会设置它。因为在成功上传后我无法捕获 fileuploaded 事件。
视图.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');
});