Coder Social home page Coder Social logo

elgg_tokeninput's Introduction

Tokenizing Autocomplete for Elgg

Elgg 2.0

Replacement for Elgg's core autocomplete and userpicker

Screenshots

alt text

Features

  • User-friendly autocomplete and userpicker inputs
  • Works with entities and meta tags
  • Developer-friendly
  • Single and multiple selection
  • Free tagging
  • Drag&Drop sorting of tokens

Notes

I/O

Default behavior of the JS plugin is to implode user input into a comma-separated string. PHP plugin hook for 'action', 'all' will attempt to explode these values and feed them back into an action for further processing. This however, will only work with basic form input names, e.g. name="field_name" If you are working with more complex forms, where e.g. name="field_name[element_name]", you will need to add some custom logic to your action.

AJAX requests

To initialize a tokeninput upon successfull AJAX request, use $('.elgg-input-tokeninput').trigger('initialize');

Results and Token Format

Server Side

Use 'tokeninput:entity:export', $entity_type plugin hook to modify json output. You can add 'html_result' and 'html_token' parameters to customize the output.

Client Side

Use 'results:formatter', 'tokeninput' and 'results:formatter', 'tokeninput' hooks.

Examples

Example 1

Create an input that would allow users to search and select multiple files to be attached to an entity:

Add an input to the form:

echo elgg_view('input/tokeninput', array(
		'value' => $current_attachment_guids, // An array of values (guids or entities) to pre-populate the input with
		'name' => 'attachment_guids',
		'callback' => 'my_search_files_callback',
		'query' => array('simpletype' => 'image'),
		'multiple' => true
	));

Add a callback function:

function my_search_files_callback($query, $options = array()) {

	$user = elgg_get_logged_in_user_entity();
	$simpletype = get_input('simpletype');

	$query = sanitize_string($query);

	// replace mysql vars with escaped strings
	$q = str_replace(array('_', '%'), array('\_', '\%'), $query);

	$dbprefix = elgg_get_config('dbprefix');

	$options['types'] = array('object');
	$options['subtypes'] = array('file');
	$options['joins'][] = "JOIN {$dbprefix}objects_entity oe ON oe.guid = e.guid";
	$options['wheres'][] = "oe.title LIKE '%$q%'";
	$options['wheres'][] = "e.owner_guid = $user->guid";

	if ($simpletype) {
		$options['metadata_name_value_pairs'] = array(
			'name' => 'simpletype', 'value' => $simpletype
		);
	}

	return elgg_get_entities_from_metadata($options);

}

In your action file:

$attachment_guids = get_input('attachment_guids');
if (is_string($attachment_guids)) {
	$attachment_guids = explode(',', $attachment_guids);
}
if (is_array($attachment_guids)) {
	foreach ($attachment_guids as $attachment_guid) {
		make_attachment($entity->guid, $attachment_guid);
	}
}

Upgrades

To 4.x

  • elgg.tokeninput library has been removed. elgg_load_library('elgg.tokeninput') calls will WSOD, just remove them

  • tokeninput/init AMD module has been removed. Tokeninput is bootstrapped as needed on page load and on ajax requests.

  • define('ELGG_TOKENINPUT_PAGEHANDLER', 'tokeninput'); has been removed. If you need to modify page handler identifier, unregister the page handler and register a new one

Attributions / Credits

elgg_tokeninput's People

Contributors

hypejunction avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

elgg_tokeninput's Issues

jquery.tokeninput error

Hello sir,

I want to use your plug-in with an elgg 2.3 version, but when I add an input/tokeninput in my form, i got " Script error for "jquery.tokeninput", needed by: tokeninput/lib" message in my JavaScript console.

Is this plug-in not working with Elgg 2.3 ?

Core input/userpicker stops working

I have Clodtrick´s Todos plugin installed (https://github.com/ColdTrick/todos), and it uses input/userpicker in views\default\forms\todos\todoitem\edit.php but if I enable elgg_tokeninput plugin, users (asignee) selection stops working.

This is the code:

`
$list = get_entity($container_guid);
if (!empty($list) && elgg_instanceof($list->getContainerEntity(), 'group')) {
echo '' . elgg_echo('todos:todoitem:assignee') . '';
echo '';
echo elgg_view('input/userpicker', array(
'value' => $assignee,
));
echo '';
}

`

The 'z-index' value is not high enough

I have seen that in the last 'release' the CSS file has been modified to solve the visualization of the autocompletion results. With which I am very grateful. The problem I have is when autocompletion is displayed on an element of type '.elgg-module-popup' because its 'z-index' value is 9999.

not working in plugin settings page

If a plugin setting action is registered to save non-standard inputs (that can't be set using the 'params' magic input name) - action() is called twice therefore this hook is called twice.
The first time it sets the input as an array which is correct, the second time it sets it as an empty string.

$elgg_tokeninput_fields = get_input('elgg_tokeninput_fields');

    if ($elgg_tokeninput_fields) {
        foreach ($elgg_tokeninput_fields as $field_name) {
            $values = explode(',', get_input($field_name, ''));
            set_input($field_name, $values);
        }
        set_input($elgg_tokeninput_fields, null);
    }

Somehow the set_input($elgg_tokeninput_fields, null); doesn't seem to be working

Problem while using with messages

When I enable this plugin and send a message to someone through the messages plugin, I get a message "You did not select someone to send this to.". It seems to be related to the tokenized autocomplete input.

We're using default theme shipped with Elgg 2.0.2 and the latest version of this plugin (Composer).

Problem with message plugin

Hi. Today I have got a little problem with the message plugin and this plugin. After autocompleting the recipient of the message and sending the message, we receive the error message "We could not find the recipient in the user database". Then, I have decided to desactivate the elgg_tokeninput plugin, and the problem disappeared. I could send the message successfully.

Thanks for your atention. Regards

Too many options causes jquery to crash

One field that has 18 options selected causes jquery to crash when the form is loaded. It handles it on input, but crashes when trying to render the field when the options have been saved.

Autocomplete not working

Installed latest version with elgg 2.33 in order to use HypeInbox

Autocomplete not working - for example with compose message (either with HypeInbox or Messages) - not able to pick username - input box in compose allows users to type, but no auto suggest appears, and therefore no message can be sent (unless the user's GUID is manually entered, in which case it works fine!).

Having further researched on this issue - I find that it's identical to the one described here :

https://elgg.org/discussion/view/2577998/strange-email-issue

Here's the output in the browser console :

require.js:168 Uncaught Error: Script error for "jquery.tokeninput", needed by: tokeninput/lib
http://requirejs.org/docs/errors.html#scripterror
at makeError (require.js:168)
at HTMLScriptElement.onScriptError (require.js:1738)
makeError @ require.js:168
onScriptError @ require.js:1738

Just for the record, this issue was resolved (happily) by installing a different version of the plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.