Disable key field for begin edited if DataTables Editor

Disable key field for begin edited if DataTables Editor

bbrindzabbrindza Posts: 329Questions: 78Answers: 1

Using DataTables Editor v2.3.2 I am trying to disable this field only on editing but not creating a new record in both inline table column and form.

  fields: [
          { label: "Tab ID",
            name:  "NAV_ID",
          },
],
columns: [
           { data: "NAV_ID",
             className: 'text-left'   },
      
],

I tried this but it did not work as designed..

                 initComplete: function() {
                     editor.on('open', function(e, mode, action) {
                         if (mode === 'edit') {
                             editor.field('NAV_ID').disable();  // Disable NAV_ID in edit mode
                         } else if (mode === 'create') {
                             editor.field('NAV_ID').enable();  // Enable NAV_ID in create mode
                         }
                     });
                 }

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,722Questions: 26Answers: 5,027
    edited February 26 Answer ✓

    I think you are using the wrong parameter. The mode parameter is the form display type where action is the edit action like create or edit. See the open event docs for details.

    Also you don't need to place the open event in initComplete. The event is not dependent on Datatables initialization. Although it doesn't hurt anything if you leave it there.

    Kevin

  • bbrindzabbrindza Posts: 329Questions: 78Answers: 1

    That was it Kevin. It is now working. One other question, I would like to style the NAV_ID column cell and edit form field not to show the input border and background when it is NOT editable. Currently it gives the appearance as if it is editable.

  • kthorngrenkthorngren Posts: 21,722Questions: 26Answers: 5,027
    Answer ✓

    I copied your code into this test case and the disabled field doesn't show an input border:
    https://live.datatables.net/guwafemu/609/edit

    Possibly the problem is due to the CSS you adding in your other thread. If you still need help with this please provide a running test case that shows the issue.

    Kevin

  • bbrindzabbrindza Posts: 329Questions: 78Answers: 1

    I got this this Kevin. I just added this css to the field.

    #DTE_Field_NAV_ID {
        background-color: transparent ;
        border:none;
    }
    
  • kthorngrenkthorngren Posts: 21,722Questions: 26Answers: 5,027
    edited February 27 Answer ✓

    Does that work properly when the filed is enabled during create?

    I updated my Editor 2.3.2 test case to disable the position field when editing and it works properly:

    Based on the questions in your two threads there seems to be some sort of CSS conflicts as you shouldn't need to add anything to handle the input borders. As I suggested in your other thread start a local test case with a basic Editor and Datatables configuration to see if the styling works properly without needing to add custom CSS. If the basic test case works then start adding to it until you find the issue.

    Kevin

  • bbrindzabbrindza Posts: 329Questions: 78Answers: 1

    I got it all worked out. Thanks Kevin

Sign In or Register to comment.