Shri
Shri

Reputation: 141

How to limit total number of inputs to textExt plugin?

<textarea id="Responsible" rows="1"> </textarea>

$('#Responsible').textext({
      plugins : 'tags autocomplete',
      tagsItems : tempRrespArray
}).bind('getSuggestions', function(e, data) {
      var list = resAray,
      textext = $(e.target).textext()[0],
      query = (data ? data.query : '') || '';

      $(this).trigger('setSuggestions', 
                       {result : textext.itemManager().filter(list, query)});
});

This is my code. I want to limit the total number of inputs to one. At present it will accept n number of inputs. How to achieve this in textExt plugin?

Upvotes: 0

Views: 794

Answers (1)

Akbar Ali
Akbar Ali

Reputation: 305

I do not know if this is the right way or not. But this worked for me. You can overwrite the core function using ext provided by the plugin and by having an additional function to check the elements already in the plugin. Your Plugin initialization should look like this

$('#element').textext({
    plugins : 'tags autocomplete',
    tagsItems : Sourcearray,
    ext: {
        tags: {
            addTags: function(tags) {
                if(checkLength()) {
                    $.fn.textext.TextExtTags.prototype.addTags.apply(this, arguments);
                }
            }
        }
    }
})

and the checkLength function should be like this

function checkLength(){
    if($("#element").next().children().length === 0){
        return true;
    }
    return false;
}

Upvotes: 4

Related Questions