print validation

print validation

manjeshmanjesh Posts: 6Questions: 1Answers: 0
edited April 2017 in Free community support

hi,
i have been trying with the below code,
{
extend: 'print',
text: 'Print selected',
exportOptions: {
modifier: {
selected: true
}
}
}
i have been trying like when i click on the button it should check if the rows have been selected or not.If no rows been selected it should show message saying please select the row.The problem is when we click it shows pop up as i used this below code
jQuery('.buttons-print').on('click', function () {
var datas = table.rows('.selected').ids().toArray();
if(datas==''|| datas==undefined){
jQuery.jGrowl("Please select a invoice.", { header: 'select row',theme:'bg-blue-alt' });
}
it shows pop up but continue the print function.I want to stop the function.
please help.

Answers

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Try returning false from your function or use stopPropagation().

    Allan

  • manjeshmanjesh Posts: 6Questions: 1Answers: 0

    allan still the function gets continue no changes.

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Can you link to an example showing the issue so I can take a look into it please?

    Thanks,
    Allan

  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    Oh - it might also be worth adding return false; into your event handler.

    Allan

  • manjeshmanjesh Posts: 6Questions: 1Answers: 0

    $.noConflict;
    documentObj = jQuery(document);
    document.oncontextmenu = function() {return false;};
    documentObj.ready(function(){
    jQuery.fn.dataTable.Buttons.swfPath = 'https://mybus.esy.es/plugins/datatables/export/flashExport.swf';
    var table = jQuery('#datatable-responsive').DataTable( {
    dom: 'Bfrtip',
    responsive: true,
    bLengthChange :true,
    select :true,
    ajax: {
    url: '../modal/ClientContacts.php',
    dataSrc: 'aaData',
    method:'POST'
    },
    buttons: [
    'pageLength',

            {
                extend:'copy',
                className:'hide'
            },
            {
                ebuttonsxtend:'csv',
                className:'hide'
            },
            {
                extend:'excel', 
                className:'hide'
            },
            {
                extend:'pdf', 
                className:'hide'
            },
            {
                extend:'print', 
                className:'hide'
            },
            {
              extend: 'pdf',
              text: 'pdf selected',
              name:'pdf',
             exportOptions: {
                modifier: {
                  selected: true
                }
          }
            } ,
            {
              extend: 'print',
              text: 'Print selected',
             exportOptions: {
              modifier: {
                  selected: true
                }
              }
          }
         ],
            columns: [
              { data:'client_name', render: function (data, type, full, meta) {
                   if (data != '' ){
                       return '<a class="remove-underline" href ="'+site_url()+'admin/view/client.php?filter=0&client='+data+'">'+data+'</a>';
                   }
              }},
              { data:'contact_name'},
              { data:'contact_email'},
              { data:'contact_phone'},
              { data:'contact_position'}
          ]
    });
    var CLIPBOARD = "";
    jQuery(function(){
    jQuery(document).contextmenu({
        delegate: "tbody",
        autoFocus: true,
        preventContextMenuForPopup: true,
        preventSelect: true,
        taphold: true,
        menu: [
            {title: "Client", cmd: "client"},
                        {title: "Interactions", cmd: "client_interaction"},
                        {title: "Agreements", cmd: "client_agreements"},
            {title: "invoice", children: [
                {title: "Invoice Terms",cmd:"invoice_terms", action: function(event, ui) { alert("action callback sub1");} },
                {title: "Invoice", cmd: "invoice", tooltip: "Edit the title"},
                ]},
                        {title: "Meetings", cmd: "meetings"}    
            ],
        // Handle menu selection to implement a fake-clipboard
        select: function(event, ui) {
            var $target = ui.target;
            switch(ui.cmd){
            case "client_contact":
                CLIPBOARD = $target.text();
                break
            case "client_interaction":
                            CLIPBOARD = $target.text();
                break
            }
                var url = site_url()+"admin/view/"+ui.cmd+'.php?f=0&v='+$target.text();
                window.location.href= url;
                }
    }); 
    });
    fillSelectBox('client_name');
    loadTableFeatures(table); 
    autoComplete('position');
    
    tableFilter(table,jQuery("#filter").val(),jQuery("#value").val());
    jQuery('#dataTableSearch').on('keyup',function(){
        table.columns(0).search("").draw();
    });
    jQuery('[type=search]').on('keyup',function(){ 
        var ck_val = jQuery("input[name=table_filter]:checked").val();
        tableFilter(table,ck_val,jQuery('.dataTables_filter input').val());
    });
    //row selection
    jQuery('#tbody').on( 'click', 'tr', function () {
        jQuery(this).toggleClass('tr-selected');
    } );
    jQuery('.buttons-pdf').on('click', function () {   
      var datas = table.rows('.selected').ids().toArray();
        if(datas==''|| datas==undefined){
            jQuery.jGrowl("Please select a invoice.", { header: 'select row',theme:'bg-blue-alt' });return false;
        }
    });
    jQuery('.buttons-print').on('click', function () {   
      var datas = table.rows('.selected').ids().toArray();
        if(datas==''|| datas==undefined){
          jQuery.jGrowl("Please select a invoice.", { header: 'select row',theme:'bg-blue-alt' });
        }
    });
    jQuery('#delete').on('click', function () { 
        var datas = table.rows('.tr-selected').ids().toArray();
        if(datas==''|| datas==undefined){
            jQuery.jGrowl("Please select a client(s).", { header: 'Delete',theme:'bg-blue-alt' });
        }
        else{ 
            jQuery('#delete_modal').modal('show');
            datas = eval(datas);
            jQuery('.id').val(datas);
        }  
      });
    jQuery("#edit").on('click',(function(e) {
        var datas = table.rows('.tr-selected').data().toArray();
        if(datas==''|| datas==undefined){
            jQuery.jGrowl("Please select a contact.", { header: 'Edit',theme:'bg-blue-alt' });
        }
        else if(datas.length>1){
            jQuery.jGrowl("Please select only one contact.", { header: 'Edit',theme:'bg-blue-alt' });
        }
        else{
            jQuery('#contact_modal').modal('show');
            jQuery('#operation').val('1');
            jQuery('#id').val(datas['0']['DT_RowId']);
            jQuery('#client_name option:contains('+datas['0']['client_name']+')').attr('selected','selected');
            jQuery('#contact_name').val(datas['0']['contact_name']);
            jQuery('#contact_email').val(datas['0']['contact_email']);
            jQuery('#contact_phone').val(datas['0']['contact_phone']);
            jQuery('#contact_position').val(datas['0']['contact_position']);
            jQuery('#contact_remarks').text(datas['0']['contact_remarks']);           
            jQuery('#created_by').val(datas['0']['created_by']);           
        }  
    }));
    jQuery("#add").on('click',(function(e) {
        jQuery('#operation').val('0');
        jQuery('#contact_form').parsley().reset();
    }));
    jQuery(".btn_close").on('click',(function(e) {
        jQuery('#contact_form').parsley().reset(); //clear parsley color validations and msg
        jQuery('#contact_form').trigger('reset');  // to clear form fields
    }));
    jQuery("#contact_form").on('submit',(function(e) {
        e.preventDefault();
        var a = [  ['client_name','client name','1'],
                   ['contact_name','contact name','0'],
                   ['contact_email','contact email','0'],
                   ['contact_phone','contact phone','0'],
                   ['contact_position','contact position','0']
                ],operation = jQuery('#operation').val();
        if(validateAll(a)){
            $.ajax({
              url: "../controller/client_contact_controller.php",
              type: "POST",
              data:  new FormData(this),
              dataType:'json',
              contentType: false,
              cache: false,
              processData:false,
              success: function(response) {
                notification(response.status);
                table.ajax.reload();
                jQuery('.btn_close').click();
              }
            });
        }    
    }));
    jQuery("#contact_form_delete").on('submit',(function(e) {
         e.preventDefault();
        jQuery.ajax({
              url: "../controller/client_contact_controller.php",
              type: "POST",
              data: new FormData(this),
              dataType:'json',
              contentType: false,
              cache: false,
              processData:false,
              success: function(response) {
                notification(response.status);  
                table.ajax.reload();
                jQuery('.btn_close').click();
              }
        });
    }));  
    

    });

  • manjeshmanjesh Posts: 6Questions: 1Answers: 0

    when i click on pdf button it should accept and work only when row is selected

    hiii.png 178.4K
  • allanallan Posts: 63,075Questions: 1Answers: 10,384 Site admin

    If you link to a test case showing the issue, I'd be happy to take a look into it.

    Allan

  • manjeshmanjesh Posts: 6Questions: 1Answers: 0

    in the picture when i click on a pdf button and when no rows are selected it should show message as please select the row.But here the pop up alert message is showing but the function pdf is working at same time.it should not work when no ows are selected

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Allan asked for a link to a test case.

    If you link to a test case showing the issue, I'd be happy to take a look into it.

This discussion has been closed.