Search code examples
javascriptjqueryhtmljquery-textext

Get textext tags in javascript?


Hello Everyone i have this problem and really don't know how to solve it: i'm using Textext tool to my website ,i type all my tags in the textarea but when i need the tags i can't get them here is my code:

html code:

<textarea id="tagsa" rows="1" cols="70" style="color: black;"   placeholder="Add Your Article Tags.. Max=7" ></textarea>

and here is my textext jquery code:

 function checkLength() {
            if ($("#tagsa").next().children().length < 7) {
                return true;
            }
            return false;
        }

$('#tagsa').textext({
    plugins: ' prompt  autocomplete ajax arrow clear  suggestions tags',
    prompt: 'Add one...',
    ajax: {
        url: '../data.json',
        dataType: 'json',
        cacheResults: true
    },
    tagsItems: eval(get_suggestion()),
    //eval(get_suggestion()),
    ext: {
        tags: {

            addTags: function (tags) {

                if (checkLength()) {
                    $.fn.textext.TextExtTags.prototype.addTags.apply(this, arguments);
                }

                else
                    alert("Only 7 Tags Allowed");

            }
        }
    }
}).bind('tagClick', function (e, tag, value, callback) {
    var url = "Finder.aspx?tag=" + value;
    window.location = url;
}).bind('isTagAllowed', function (e, data) {
    var formData = $(e.target).textext()[0].tags()._formData,
        list = eval(formData);

    // duplicate checking
    if (formData.length && list.indexOf(data.tag) >= 0) {

        data.result = false;
    }
});

i tried this:

  alert(document.getElementById("tagsa").value)

but it doesn't show me the inner text/tags

can any one help me with this?


Solution

  • I couldn't find this operation in the plugin's docs, but after diving in the code I found a way.

    $('#textarea').textext({
      plugins: 'tags',
      tagsItems: [ 
        'PHP', 'Closure', 'Java' 
      ]
    });
    
    $('#btn').click(function(){
      var tags = $('#textarea').textext()[0].tags()._formData;
      
      $('#result').html(JSON.stringify(tags));
    });
    <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-textext/1.3.0/jquery.textext.min.js"></script>
    
    <textarea id="textarea"></textarea><br />
    <button id="btn">Show Tags</button>
    <hr />
    <pre id="result"></pre>

    http://jsbin.com/joquga