vkabachenko/yii2-filepond

Yii2 upload file module based on filepond js library

Installs: 495

Dependents: 0

Suggesters: 0

Security: 0

Stars: 5

Watchers: 2

Forks: 7

Open Issues: 1

Type:yii2-extension

dev-master 2020-03-07 10:27 UTC

This package is not auto-updated.

Last update: 2024-12-22 10:01:07 UTC


README

This extension allows you to use Filepond upload js library as a widget in yii2 projects.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require  vkabachenko/yii2-filepond

or add

"vkabachenko/yii2-filepond": "dev-master"

to the require section of your composer.json file.

Usage

Add the extension to the module section in your config file

    'modules' => [
       'filepond' => [
           'class' => \vkabachenko\filepond\Module::class
       ]
    ],

After that you can use Filepond library to upload files in your project.

Single file upload without model

Single file upload with model

Multiple files upload without model

Multiple files upload with model

Filepond options

Filepond options described at the documentation can be set by setting instanceOptions or settingsOptions.

This is the preferred way:

    <?= FilepondWidget::widget([
            'name' => 'file',
            'instanceOptions' => [
                'required' => true,
                'maxFiles' => 10,
                ... other options ...
            ]
         ]);
    ?>

Filepond plugins

If you want to add some of filepond plugins to the widget, set the allow plugin option to true. For example, to add file type validation plugin set allowFileSizeValidation:

    <?= FilepondWidget::widget([
            'name' => 'file',
            'instanceOptions' => [
                'allowFileSizeValidation' => true,
                'maxFileSize' => '10M',
                ... other options ...
            ]
         ]);
    ?>

Validation

Only client-side validation is available. This kind of validation is the part of filepond library. You can add file size and file type validation. Example of file type validation:

    <?= FilepondWidget::widget([
            'name' => 'file',
            'instanceOptions' => [
                'allowFileTypeValidation' => true,
                'acceptedFileTypes' => ['image/*']
            ]
                ... other options ...
            ]
         ]);
    ?>

Localization

Original library isn't localized and has only english labels. This widget has russian translations too. To apply the localization you have to set language option in Yii settings or directly in the widget:

    <?= FilepondWidget::widget([
            'name' => 'file',
            'language' => 'ru-RU'
         ]);
    ?>

Two or more widget instances on the page

Simply separate widget class definitions.

Widget 1:

    <?= FilepondWidget::widget([
            'filepondClass' => 'filepond-class-1',
            'name' => 'file',
            'instanceOptions' => [
                ... first widget options ...
            ]
         ]);
    ?>

Widget 2:

    <?= FilepondWidget::widget([
            'filepondClass' => 'filepond-class-2',
            'model' => $uploadForm,
            'attribute' => 'files[]',
            'instanceOptions' => [
                ... second widget options ...
            ]
         ]);
    ?>