Ravenclaw
Ravenclaw

Reputation: 51

How to disable adding new tags in bootstrap tagsinput?

I'm going to use bootstrap tagsinput without adding new tags feature (only remove tags). How to disable adding new tags?

I'm using latest bootstrap tagsinput v0.8.0 with twitter bootstrap 3.

Here is my snippet:

<input id="removeonlyinput" type="text" value="Amsterdam,Berlin,Lisbon" data-role="tagsinput" />

<script>
$('#removeonlyinput').tagsinput({
      freeinput: false
});
</script>

Upvotes: 2

Views: 5726

Answers (5)

Bhargav Chaniyara
Bhargav Chaniyara

Reputation: 44

it's not

freeinput: false

it's

freeInput: false

Upvotes: 0

kendev
kendev

Reputation: 27

you can do this

$( "#removeonlyinput" ).prop( "disabled", true );

don't mind the extra spaces.

Upvotes: 1

Chandan
Chandan

Reputation: 235

How about making the input field readonly ? By this no user can type in the input text.

$('input[type=text]').prop("readonly", true);

Upvotes: 4

DenysM
DenysM

Reputation: 389

Try to use beforeItemAdd event:

$('#removeonlyinput').on('beforeItemAdd', function(event) {
  event.cancel = true;
});

Upvotes: 2

neophyte
neophyte

Reputation: 6626

You can modify bootstrap-tagsinput.js file.

find maxTags:, line and make it maxTags: 0,

Then it won't add new tags.

In this way I achieved the functionality. Hope this helps!

Upvotes: 1

Related Questions