validation inside a dialog

validation inside a dialog

Hi,

I have a dialog box that is working fine, the end user has to check one or more checkboxes before pressing the button "Assign", I want to have  a validation before submitting, if no checkbox  were checked it should diaply an error validation, here is my code :

I would like to check if the array    agenciesId is empty, display an error and don't submit.

  1.  $("#divPopUp").dialog({
  2.         resizable: true,
  3.         autoOpen: false,
  4.         height: 500,
  5.         width: 550,
  6.         modal: true,
  7.         buttons: {
  8.             "Assign": function () {
  9.                   var agenciesId = $(this).find(":checkbox:checked").map(function () {
  10.                     return this.value;
  11.                 }).get();
  12.                  //alert("agenciesId :" + agenciesId);
  13.                  var ruleIDd = $("#divPopUp").data('param_1');
  14.                  $.ajax({
  15.                 url: 'assignRenameRuleToAgency.do',
  16.                 data: {"agenciesId": agenciesId,"ruleId":ruleIDd },
  17.                 success: function(response) {
  18.                    toastr.success(response.message);
  19.                            oTable.draw(false);  
  20.                    //oTable.fnStandingRedraw();
  21.                 }     
  22.             });  
  23.                 $(this).dialog("close");
  24.             },
  25.             Cancel: function () {
  26.                 $(this).dialog("close");
  27.             }
  28.         },
  29.         close: function () {
  30.             $(this).find(":checkbox").removeAttr('checked');
  31.             $(this).dialog("close");
  32.         }
  33.     });

Thanks.