elinw/joomla-cms — pull request #75 by phproberto (2013-03-09 10:49:22+00:00)
Title: Sample Tag field for article management

AJAX field for tags
===============
This integrates the AJAX chosen library by Ryan LeFevre:
https://github.com/meltingice/ajax-chosen

The field
-------------

* Instead of showing a list of nested tags (imagine what happens when you have hundreds of tags) my proposal is to search tags with AJAX while the user writes (3 chars minimum are required). Most tag systems use this.
* New tags can be added on the fly. Writing and pressing enter.

Sample integration
-------------------------------
Integrating the field in a form is quite easy.

Field has to be declared as tag field in the form XML:

```XML

```
Then in the edit window we set the ajax-chosen data:
```PHP
// Tags field ajax
$chosenAjaxSettings = new JRegistry(
array(
'selector' => '#jform_tags',
'type' => 'GET',
'url' => JURI::root() . 'index.php?option=com_tags&task=tags.searchAjax',
'dataType' => 'json',
'jsonTermKey' => 'like'
)
);
JHtml::_('formbehavior.ajaxchosen', $chosenAjaxSettings);
```
That's it. Easy true?

In fact maybe we can make it easier creating the options in the formbehaviour library and only receive the selector from the users. But that can limit the use of the tag field.

ToDo
--------

* Add translations for the strings in the field
* Add a button to submit the tags (accesibility) ?
* Currently the tag uses a #new# prefix to identify new tags. Decide if this is ok.
* Currently the user has to write 3 chars to get the AJAX launched. Maybe we have to add a parameter to allow the user to customize it.