user2873816
user2873816

Reputation: 179

How can I disable bootstrap dropdown list

I made a dropdown list using bootstrap.Dynamically I want to disable and enable the dropdown list.

html code:

  <div class="span3 offset1">
        <select name="primary" class="select-block" id="select_alert" style="display: none;">
            <option "selected"="">Choose Alert T</option>                         


    <option value="T1">T1</option>

    <option value="T2">T2</option>

    <option value="T3">T3</option>

    <option value="T4">T4</option>

</select>
<div class="btn-group select select-block">
  <i class="dropdown-arrow dropdown-arrow-primary"></i>
  <button class="btn dropdown-toggle clearfix btn-primary" data-toggle="dropdown" id="select_alert">
    <span class="filter-option pull-left">Choose Alert T</span>&nbsp;
    <span class="caret"></span>
  </button>
  <ul class="dropdown-menu dropdown-primary" role="menu">
    <li rel="0" class="selected">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">Choose Alert T</span>
      </a>
    </li>
    <li rel="1">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T1</span>
      </a>
    </li>
    <li rel="2">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T2</span></a>
    </li>
    <li rel="3">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T3</span>
      </a>
    </li>
    <li rel="4">
      <a tabindex="-1" href="#" class="">
        <span class="pull-left">T4</span>
      </a>
    </li>
  </ul>
  </div>
</div>

some times I want to disable and sometimes I want to enable.So How can I do this. In this I have 2 more dropdown elemnts.All are placed in singlw div tag.Here I didn't mention that div tag id name.I just putted single dropdown element code.

Upvotes: 2

Views: 28218

Answers (4)

Catalyst
Catalyst

Reputation: 465

If above solutions does not work for you, the try

$('#yourDropDownElement').prop('disabled', true).trigger('chosen:updated');

I'm using boostrap v 3.3.6

Upvotes: 0

rajkjaiswal
rajkjaiswal

Reputation: 1

You can do this by add if block on the property and add disabled class to the drop down.

below is my div in that i have eanbled/disabled dropdown toggle button on IsNewEditDisabled

<button ng-if="!IsNewEditDisabled" class="btn dropdown-toggle" ng-class="{open: status.isopen}" dropdown-toggle>
                                <i class="fa fa-pencil"></i><span class="caret"></span>
                            </button>
                            <button ng-if="IsNewEditDisabled" class="btn dropdown-toggle disabled" ng-class="{open: status.isopen}" dropdown-toggle>
                                <i class="fa fa-pencil"></i><span class="caret"></span>
                            </button>

Upvotes: -2

JERRY-the chuha
JERRY-the chuha

Reputation: 582

Yes, by jquery you can get this:

Here is the example:

http://jsfiddle.net/jV7ye/

$(document).ready(function() {
    $("#chkdwn2").click(function() {
       if ($(this).is(":checked")) { 
          $("#dropdown").prop("disabled", true);
       } else {
          $("#dropdown").prop("disabled", false);  
       }
    });
});

UPDATED JS CODE as per your need:

$(document).ready(function() {

        if(!$("#chkdwn2").is(":checked"))
        {
            $("#dropdown").prop("disabled",true);
        }

        $("#chkdwn2").click(function() {
           if ($(this).is(":checked")) { 
              $("#dropdown").prop("disabled", false);
           } else {
              $("#dropdown").prop("disabled", true);  
           }
        });
    });

Replace dropdown id with your id. Thanks

Upvotes: 8

Sridhar R
Sridhar R

Reputation: 20428

By using jquery we can do

Disable Dropdown

$('.select_alert').attr('data-toggle','');

Enable Dropdown

$('.select_alert').attr('data-toggle','dropdown');

Upvotes: 3

Related Questions