Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/infinityloop-dev/ajaxselect
:wrench: Ajax-filled select box for Nette forms.
https://github.com/infinityloop-dev/ajaxselect
ajax ajaxselect form nette php
Last synced: 5 days ago
JSON representation
:wrench: Ajax-filled select box for Nette forms.
- Host: GitHub
- URL: https://github.com/infinityloop-dev/ajaxselect
- Owner: infinityloop-dev
- License: mit
- Created: 2019-01-12T20:29:02.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-02T20:29:33.000Z (almost 2 years ago)
- Last Synced: 2024-04-03T01:23:25.000Z (8 months ago)
- Topics: ajax, ajaxselect, form, nette, php
- Language: PHP
- Homepage: https://www.infinityloop.dev
- Size: 37.1 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ajaxselect
:wrench: Ajax-filled selectbox for nette forms.![Packagist](https://img.shields.io/packagist/dt/nepttune/ajaxselect.svg)
![Packagist](https://img.shields.io/packagist/v/nepttune/ajaxselect.svg)
[![CommitsSinceTag](https://img.shields.io/github/commits-since/nepttune/ajaxselect/v1.0.svg?maxAge=600)]()[![Code Climate](https://codeclimate.com/github/nepttune/ajaxselect/badges/gpa.svg)](https://codeclimate.com/github/nepttune/ajaxselect)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/nepttune/ajaxselect/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/nepttune/ajaxselect/?branch=master)## Introduction
This extension provides easy to use ajax-driven selectbox.
## Dependencies
- [nepttune/base-requirements](https://github.com/nepttune/base-requirements)
## How to use
- Register `\Nepttune\DI\AjaxSelectExtension` as nette extension.
- Use `addAjaxSelect` or `addAjaxMultiSelect` in your forms.### Example configuration
```
extensions:
ajaxSelect: Nepttune\DI\AjaxSelectExtension
```### Example form
```php
$form->addAjaxSelect('client_id', 'Klient', function (string $query, ?int $default = 0) {
if ($default) {
$row = $this->repository->getRow($default);
return [$row->id => $row->name];
}return $this->repository->search($query);
})
->setPrompt('--- Vyberte ---')
->setRequired();
```Parameter `$query` contains text being searched, parametered `$default` contains value which is set as default (for example when editing existing entry, you need to provide saved key => value in your callback).
### Javascript snippet using select2
```js
if ($(this).data('ajaxselect')) {
$(this).select2({
tokenSeparators: [',', ' '],
ajax: {
url: $(this).data('ajaxselect'),
delay: 250,
dataType: 'json',
data: function (params) {
return {
q: params.term
};
},
processResults: function (data, params) {
var result = [];
$.each(data, function (key, value) {
result.push({
id: key,
text: value
});
});
return {
results: result
};
}
}
});
}
```