Hello Cole,
I set up a plugin so that the user could type in 3 chars and the system would match that to existing tags using ajax GET. I could not get it to add extra tags.
I use a simple form.xml file:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="tags">
<fieldset name="details">
<field name="name" id="name" type="text" hint="Full Name" class="advancedSelect" label="Text" description="Text"/>
<field name="tags" id="tagfield" type="tag" label="JTAG" custom="allow" description="Tags" mode="ajax" class="inputbox small" multiple="true" />
</fieldset>
</fields>
</form>
and then a simple php file. This calls in the relevant joomla javascript.
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\Registry\Registry;
use Joomla\CMS\Uri\Uri;
$ajaxSettings = new Registry(array(
'selector' => 'tagfield',
'url' => Uri::root() . 'index.php?option=com_tags&task=tags.searchAjax'
));
HTMLHelper::_('jquery.framework');
HTMLHelper::_('formbehavior.ajaxchosen', $ajaxSettings);
/**
* A content plugin for adding bootstrap tabs to articles that have Regular Labs tabs
* embedded in them.
*
* @since 1.6
*/
class PlgContentTestTags extends CMSPlugin
{
/**
* On content preparation modify urls and article text
*
* @param string $context The context for the content.
* @param reference $article A reference to the article being rendered by the view.
* @param reference $params A reference to an associative array of relevant parameters
* @param integer $page The page of the content that is to be generated
*
* @return none A boolean might be returned to check for success or failure
*
* @since 1.6
*/
public function onContentPrepare($context, &$article, &$params, $page)
{
// Factory applications
$app = Factory::getApplication();
// Don't run this plugin when the content is being indexed
if ($context != 'com_content.article') {
return true;
}
// Simple content check to determine whether plugin should process further
if (strpos($article->text, '{tags}') === false) {
return true;
}
$txt = '';
if ($form = $this->getForm()) {
$txt .= '<form method="post" class="tagsForm form-horizontal" type="form" id="tagsForm" name="tagsForm" action="">';
$txt .= '<fieldset class="tags_form">';
$txt .= $form->renderFieldset('details');
$txt .= '</fieldset">';
$txt .= '<fieldset class="submit-tags">';
$txt .= '<div><button class="btn btn-primary" type="submit" value="Submit" title="Subscribe request">Sign up</button></div>';
$txt .= '</fieldset>';
$txt .= '</form>';
} else {
$txt .= 'Warning: Could not find tags form!';
}
$article->text = str_replace('{tags}', $txt, $article->text);
}
/**
* Prepare the form for display
*/
private function getForm() {
$form = new Form('tagsForm');
$form->addFormPath(JPATH_BASE . '/plugins/content/testtags/forms');
$form->loadFile('form', false);
return $form;
}
}
I didn't bother with helper files and the js is part of joomla.
I hope that helps.
Regards,
Peter.