0

我尝试为 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');
});
4

1 回答 1

1

在选项列表中移动 id:

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

你可以在文档中找到它

于 2017-07-06T17:28:59.203 回答