Disable key field for begin edited if DataTables Editor
Disable key field for begin edited if DataTables Editor
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
I think you are using the wrong parameter. The
mode
parameter is the form display type whereaction
is the edit action likecreate
oredit
. See theopen
event docs for details.Also you don't need to place the
open
event ininitComplete
. The event is not dependent on Datatables initialization. Although it doesn't hurt anything if you leave it there.Kevin
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.
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
I got this this Kevin. I just added this css to the field.
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
I got it all worked out. Thanks Kevin