Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom render #19

Open
bbrossaud opened this issue Jun 26, 2014 · 3 comments
Open

Custom render #19

bbrossaud opened this issue Jun 26, 2014 · 3 comments

Comments

@bbrossaud
Copy link

Hello,

How can I render custom tags in the input?

Actually I would like to display in my input : @toto and not how it is displayed in my autocomplete results... How can I do that?

Regards,

@daniel-zahariev
Copy link
Owner

Can you elaborate a bit more? Is @toto a tag in your example?

@bbrossaud
Copy link
Author

Sorry it was not a good example!

I use ajax request to display search result.

For example if I'm typing hello @ben

The suggestions result will be :

  • SHERKHAN (Benoit Brossaud)
  • Benji (benjamin johnson)
    ...

Currently if I select the first result (SHERKHAN (Benoit Brossaud)) my tag
in the input will be : SHERKHAN (Benoit Brossaud), so the result will be :

Hello SHERKHAN (Benoit Brossaud).

Or what I would like is :

Hello @sherkhan

So how can I have a tag display different from my search result?

I hope it will be clearer now.

Thanks for your reply,

Best regards,

@bbrossaud
Copy link
Author

I found out the solution !

Here is my code :

textareaDom.textntags({
    triggers: {'@': {
        uniqueTags: true,
        showImageOrIcon: true,
        parser: /(@)\[\[(\d+):([\w\s\.\-]+):([\W\w\s@\.,-\/#!$%\^&\*;:{}=\-_`~()]+)\]\]/gi,
        keys_map: {
            id: 'id',
            title: 'tagRendering',
            name: 'name',
            description: '',
            img: 'avatar',
            no_img_class: 'icon',
            type: 'type'
        },
    }},
    templates: {
        tagsListItem      : _.template('<li><%= name %></li>'),
    },
    realValOnSubmit: false,
    onDataRequest:function (mode, query, triggerChar, callback) {
        var request = $.ajax({
            url: s_url_json_search_friend,
            type: "GET",
            data: {search: query},
        });

        request.done(function(data) {
            var response = data.response;
            callback.call(this, response);
        });

        request.fail(function(jqXHR, textStatus) {
            console.log("Ajax request failed: " + textStatus);
        });
    }
});

what is important is : tagsListItem : _.template('

  • <%= name %>
  • ') !

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants