0

I try to set the id for the Kartik FileInput Widget but it seems like it won't set it.. because I'm unable to catch the fileuploaded events after an successfull upload.
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');
});
csminb
  • 2,382
  • 1
  • 16
  • 27
Phil
  • 107
  • 1
  • 7

1 Answers1

1

move the id inside the option list:

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

you can find it in the docs

csminb
  • 2,382
  • 1
  • 16
  • 27