Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery TextExt Plugin: add tag after keypress "space" and click on some button

I have one input

<input type="text" style="width:200px" id="myInputTags" placeholder="add tag" />
<input type="button" id="btnId" />

in script

jQuery("#myInputTags").textext({ plugins: 'tags' });

now when I press enter in this input the tag is created, but I want to added this tags after click on my button and after keypress "space" some proposal?

like image 462
Alex Avatar asked Oct 03 '14 17:10

Alex


1 Answers

Hi.

jQuery("#myInputTags")
    .textext({
        plugins: 'tags, prompt', 
        prompt: 'add tag'
    })
   .keypress(function(event){
     //'Space' key is pressed in keyboard
     if(event.which==32){
       addTag();
     }
   });

jQuery("#btnId").click(function(){
    addTag();
})

function addTag(){
    //Take the value from text input
    var tag = $('#myInputTags').val();

    //Clear the text input and add tag
    $('#myInputTags').val('').textext()[0]
    .tags().addTags([tag]);
}

See a Live Demo of this

Docs: TexExt - Adding Tags Directly

like image 134
Δbrhм cc Avatar answered Nov 12 '22 06:11

Δbrhм cc