2017 © Pedro PelĂĄez
 

library select2input

Select2 form input for Nette

image

tomaskarlik/select2input

Select2 form input for Nette

  • Saturday, April 7, 2018
  • by tomaskarlik
  • Repository
  • 1 Watchers
  • 0 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 48 % Grown

The README.md

Select2Input

Install

Download package, (*1)

composer require tomaskarlik/select2input
````

Register extension in ```config.neon```
```neon
select2: TomasKarlik\Select2Input\DI\Select2InputExtension

Download Select2 or add to bower.json and include JS to your project, (*2)

"dependencies": {
    "select2": "~4.0"
}
$(document).ready(function() {
    $('.select2').each(function() {
        $(this).select2({
            ajax: {
                url: $(this).data('select2-url'),
                dataType: 'json',
                // custom parameters
            }
          });
    });
});

Form usage, (*3)

$form = new Form;
$form->addSelect2('client_id', $clientRepository, 'Klient:')
    ->setRequired('Vyberte klienta!')
    ->setResultsPerPage(15);
$form->addSelect2Multiple('clients', $clientRepository, 'Klienti:')

Datasource example, (*4)

namespace App\Model\Repository;

use TomasKarlik\Select2Input\ISelect2DataSource;
use TomasKarlik\Select2Input\Select2ResultEntity;


class ClientRepository implements ISelect2DataSource
{

    /**
     * @param string $query
     * @param int $limit
     * @param int $offset
     * @return Select2ResultEntity[]
     */
    public function searchTerm(string $query, int $limit, int $offset): array
    {
        $return = [];
        $selection = $this->getClientTable()
            ->where(
                'company ILIKE ?', '%' . $query . '%'
            )
            ->order('company')
            ->select('client.id, client.company')
            ->limit($limit, $offset);

        while ($row = $selection->fetch()) {
            $result = new Select2ResultEntity;
            $result->setId($row->id);
            $result->setText($row->company);
            $return[] = $result;
        }
        return $return;
    }


    /**
     * @param string $query
     * @return int
     */
    public function searchTermCount(string $query): int
    {
        return $this->getClientTable()
            ->where(
                'company ILIKE ?', '%' . $query . '%'
            )
            ->count('*');
    }


    /**
     * @param mixed $key
     * @return Select2ResultEntity|NULL
     */
    public function findByKey($key): ?Select2ResultEntity
    {
        if ( ! is_numeric($key)) {
            return NULL;
        }

        $client = $this->getClientTable()->wherePrimary($key)->fetch();
        if ( ! $client) {
            return NULL;
        }

        $result = new Select2ResultEntity;
        $result->setId($client->id);
        $result->setText($client->company);
        return $result;
    }

}

The Versions

07/04 2018

dev-master

9999999-dev

Select2 form input for Nette

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

select2 forms input nette

07/04 2018

0.9.3

0.9.3.0

Select2 form input for Nette

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

select2 forms input nette

04/03 2018

0.9.2

0.9.2.0

Select2 form input for Nette

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

select2 forms input nette

04/03 2018

0.9.1

0.9.1.0

Select2 form input for Nette

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

select2 forms input nette