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

prefill/populate tag by default on onload #16

Open
tusharvikky opened this issue Mar 23, 2014 · 16 comments
Open

prefill/populate tag by default on onload #16

tusharvikky opened this issue Mar 23, 2014 · 16 comments

Comments

@tusharvikky
Copy link

Hello,

How can I automatically create @mention user in the textarea by default on load.

Regards

@daniel-zahariev
Copy link
Owner

Given the examples page it would be like to have the textarea's text set to: @[[3:contact:Daniel Nathans]]

@tusharvikky
Copy link
Author

A short example would be great. I tried that but didn't get that to work.

@daniel-zahariev
Copy link
Owner

Check out example 5 that i've added: http://daniel-zahariev.github.io/jquery-textntags/ - is this what you need?

@tusharvikky
Copy link
Author

I tried the same but the only problem is I have modified the syntax template. So, it displays as follow, Let me know if I am doing something wrong.

http://i.imgur.com/NB0mVxW.jpg

init function:

        var ajax_request = false;
        $('textarea.tagged_text').textntags({
        triggers: {'@': {
            uniqueTags   : true,
            syntax       : _.template('@[<%= id %>]')
        }},
          onDataRequest: function (mode, query, triggerChar, callback) {
            // fix for overlapping requests
            if(ajax_request) ajax_request.abort();

            ajax_request = $.getJSON('ajax/userJSON', {search: query}, function(responseData) {
                query = query.toLowerCase();
                responseData = _.filter(responseData, function(item) { return item.name.toLowerCase().indexOf(query) > -1; });
                callback.call(this, responseData);
                ajax_request = false;
            });

          }
        });

@daniel-zahariev
Copy link
Owner

Updating the syntax without updating the parser and parserGroups will lead you to such result. In your case you're stripping off all other data than the id but this leads to loss of data because the prefill/population does not make a call to fetch the records/data that is referenced.
Why do you need this syntax change in the first place?

@tusharvikky
Copy link
Author

I have an existing @tagging setup ready and in production right now. And its backend is parsing those records, I will have to make my backend compatible so that it can handle both syntax. Do you have any alternative or else I have to do it the hard way then. :( and enable parseGroups.

@daniel-zahariev
Copy link
Owner

Usually i use it with a hidden form field and on form submit i populate the value of this hidden field with the raw JSON which is the text parsed (from example 1, button 'Get Tags Collection'):

  $('textarea.tagged_text_ex1').textntags('getTags', function(data) {
        console.log(JSON.stringify(data), data);
    });

So here instead of logging this you can set the value of the hidden field.

@tusharvikky
Copy link
Author

Great. 👍 It worked.

@tusharvikky
Copy link
Author

hey @daniel-zahariev This might sound a little n00bish but how can I bind textntags to ajax loaded contents?

@aseemsharma16
Copy link

@tusharvikky are you able to bind textntags to ajax loaded contents ?

@tusharvikky
Copy link
Author

@aseemsharma16 I dont know if that's the right way but I just called textntags again after ajax request completes.

@aseemsharma16
Copy link

@tusharvikky As I making ajax request and adding the plaintext to the textarea using jquery and html div to textntags-beautifier > div but when try to change textarea text or edit something it removes previous tags. can you provide me the code example

@tusharvikky
Copy link
Author

http://daniel-zahariev.github.io/jquery-textntags/ Ex. 5 will help you. Dont create any div. Just place textarea with appropriate value, call textntags again after that ajax request and it will create that div all by itself.

@aseemsharma16
Copy link

@tusharvikky it worked thanks :)

@aseemsharma16
Copy link

@tusharvikky , one more help, I am getting an issue, when the list of users comes and I want to click the username to select the user i want to tag, can you help me in that.

@tusharvikky
Copy link
Author

textntags is perfect for that. I doubt if any bugs exists.

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

3 participants