user1421432
user1421432

Reputation: 103

selectable limit

am trying to add limit of 6 selectable rows but i can't make it work. Any help!!

<script>
$(function() {
  $(".selectable").selectable({
      filter: "td.cs",


      stop: function() {
          var result = $("#select-result").empty();
          var result2 = $("#result2");
          $(".ui-selected", this).each(function() {

              var cabbage = this.id + ', ';
              result.append(cabbage);
          });

          var newInputResult = $('#select-result').text();
          newInputResult = newInputResult.substring(0, newInputResult.length - 1);
          result2.val(newInputResult);
      }
  });
 });​
 </script>

I amtrying to add this source code below into the one above

$( "#selectable" ).selectable({
   selecting: function(event, ui) { 
     if ($(".ui-selected, .ui-selecting").length > 4) {
       $(ui.selecting).removeClass("ui-selecting");
     }
   }
});

Anyone?? Thanks

Upvotes: 0

Views: 167

Answers (1)

thecodeparadox
thecodeparadox

Reputation: 87073

$("#selectable").selectable({
    filter: 'li:lt(4)',
    selecting: function(event, ui) {
        $('ui.selecting')
        $('.ui-selecting:gt(3)').removeClass("ui-selecting");
    }
});

For more about :lt(), here

You don't give your html code in post. but you can try this:

 filter: "table.selectable > tr > td.cs:lt(4)"

DEMO

Upvotes: 1

Related Questions