DataTables Editor onEsc

DataTables Editor onEsc

Josh_BrooksJosh_Brooks Posts: 11Questions: 4Answers: 0

Is there an example of initializing the DataTables Editor 1.4 with the onEsc option? I'm trying to prevent the escape button from closing the editor form.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    You could use formOptions.main if you are using the main editing form:

    var editor = new $.fn.Editor( {
        ajax:  "php/staff.php",
        table: "#myTable",
        formOptions: {
            main: {
                onEsc: 'none'
            }
        }
    } );
    

    See also the onEsc documentation.

    Allan

  • Josh_BrooksJosh_Brooks Posts: 11Questions: 4Answers: 0

    I'm using the bubble editor. I tried adding the onEsc function in a number of ways but to no effect. Would this be the correct syntax?

    editor = new $.fn.dataTable.Editor({
          ajax:{"url":URL},
          table:TABLE_ID,
          formOptions:{
            bubble:{
              title:"Edit",
              buttons:false,
              onEsc: 'none'
            }
          }
    
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Yes that looks correct. Can you show me how you are calling the bubble() method. You could try passing { onEsc: 'none' } as the second parameter to that method.

    Allan

  • Josh_BrooksJosh_Brooks Posts: 11Questions: 4Answers: 0

    Here is how I am opening the editor form:

      var addNewRowToTable = function(e) {
        if (e != 'undefined' && e != null) {
          e.preventDefault();
        }
        formFunction = '';
        disableCommonFlowCommands = true;
        editor.title("Add New Row").buttons([{
          className: "ui-button-icon-primary",
          label:"Add",
          fn:function() {
            formFunction = 'Add';
            editor.submit();
          }
        },{
          label:"Add & Close",
          className: "ui-button-icon-primary primary",
          "fn":function() {
            formFunction = 'AddAndClose';
            editor.submit();
          }
        }, {
          label:"Cancel",
          fn:function() {
            formFunction = 'Cancel';
            this.close();
          }
        }]).create();
    
  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    Try changing:

    .create();

    to be:

    .create( { onEsc: 'none' } );
    

    However, create() is for the main form editor - it will not triggering the bubble editing that you mentioned you were using before.

    Allan

  • Josh_BrooksJosh_Brooks Posts: 11Questions: 4Answers: 0

    So, onEsc doesn't trigger for the bubble form? Is my only option to turn it into a main form?

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin
    Answer ✓

    onEsc should work okay with Bubble editing. As an example if you load the basic Editor example and then open your browsers' Javascript console and enter:

    $('#example').on( 'click', 'tbody td', function () {
      editor.bubble( this, { onEsc: 'none' } );
    } );
    

    Click on a cell to activate the bubble editor and then try pressing the escape key. It shouldn't close the bubble (it doesn't in my tests such now).

    Allan

This discussion has been closed.