Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if select all option is checked in sumoselect

I have just come across SumoSelect.js for dropdowns in my MVC project. I just wanted to know if there is way to know if the select all option of the sumoselect dropdown is checked or not. This is my sumoslect drop down code.

   <div>
    @Html.LabelFor(m => m.Territory)
    @Html.DropDownListFor(m => m.Territory, Model.Territories, new { @class = "form-control", id = "ddlTerritory", multiple = "multiple", placeholder = "Select Territory" })
    @Html.ValidationMessageFor(m => m.Territory)
   </div>

JavaScript Code

 $(document).ready(function () 
  {
    $('#ddlTerritory').SumoSelect({ selectAll: true });
    if ($('#ddlTerritory')[0].sumo.selectAll())
        {
           some code
        }
  }

There is no mention of such method in the documentation of sumoselect. It would be great if some one can guide me in the right direction.

Edit: As Suggested by @stephen

$(document).ready(function () 
      {
        $('#ddlTerritory').SumoSelect({ selectAll: true });
var isChecked = $('#ddlTerritory').closest('.SumoSelect').find('.select-all')‌​.hasClass('.select')‌​;
        if (isChecked)
            {
               some code
            }
      }
like image 693
Shekar.gvr Avatar asked Nov 17 '25 15:11

Shekar.gvr


1 Answers

this quite tricky, that I count selected items with total options:

function isMultipleSelectAll(id) {
    var ids = $(id).val();
    let options = $(id + " option");

    let totalSelected = ids.length;
    let totalOptions = options.length;

    if (totalSelected >= totalOptions) {
        return true;
    } else {
        return false;
    }
}
like image 97
Lê Văn Hiếu Avatar answered Nov 19 '25 04:11

Lê Văn Hiếu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!