Skip to content
🔤 Form component for token input label.
PHP JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
examples
src
tests
.gitignore
.scrutinizer.yml
.travis.yml
README.md
composer.json
license.md

README.md

Downloads this Month Latest Stable Version

This is Nette adaptation for: https://github.com/bootstrap-tagsinput/bootstrap-tagsinput

Installation

Composer:

composer require achse/nette-tag-input

And: composer update achse/nette-tag-input

Javascript Dependencies

npm install jquery
npm install bootstrap3
npm install bootstrap-tagsinput
npm install typeahead.js

If you are using webloader:

webloader:
	css:
		default:
				- %wwwDir%/../node_modules/bootstrap3/dist/css/bootstrap.min.css
				- %wwwDir%/../node_modules/bootstrap3/dist/css/bootstrap-theme.min.css
				- %wwwDir%/../node_modules/bootstrap-tagsinput/dist/bootstrap-tagsinput-typeahead.css
				- %wwwDir%/../node_modules/bootstrap-tagsinput/dist/bootstrap-tagsinput.css

	js:
		default:
			files:
				- %wwwDir%/../node_modules/jquery/dist/jquery.js
				- %wwwDir%/../node_modules/bootstrap3/dist/js/bootstrap.min.js
				- %wwwDir%/../node_modules/typeahead.js/dist/typeahead.bundle.js
				- %wwwDir%/../node_modules/bootstrap-tagsinput/dist/bootstrap-tagsinput.js
				- %wwwDir%/../vendor/achse/nette-tag-input/assets/tagInput.js

Nette Form

You just add this code to your BaseForm or trait or whattever adds addXyzInput to your forms:

/**
	 * @param string $name
	 * @param string $label
	 * @param DataSourceDescriptor $dataSourceDescriptor
	 * @return TagInput
	 */
	public function addTagInput($name, $label, DataSourceDescriptor $dataSourceDescriptor)
	{
		$input = new TagInput($dataSourceDescriptor, $label);

		return $this[$name] = $input;
	}

And usage:

$form = new BaseForm();

$form->addTagInput(
	'to',
	'Send to',
	new DataSourceDescriptor($this->linkGenerator->link('SomeModule:SomePresenter:users'))
);

On that URL given by last argument should be something in format like this:

public function renderUsers()
{
	$array = [
		(object) [
			DataSourceDescriptor::DEFAULT_VALUE_PROPERTY => 1,
			DataSourceDescriptor::DEFAULT_LABEL_PROPERTY => 'František Dobrota',
		],
		(object) [
			DataSourceDescriptor::DEFAULT_VALUE_PROPERTY => 2,
			DataSourceDescriptor::DEFAULT_LABEL_PROPERTY => 'Boris Yeltsin',
		],
	];

	$this->sendResponse(new JsonResponse($array));
}
You can’t perform that action at this time.