dependent show/hide/disable/enable
dependent show/hide/disable/enable
in Editor
I have a field with a dependent function to show a field if a certain value is chosen in another field - so far so good. However this dependant field gets a value from the data and if that value is > 0 it enters the value but then the field should be disabled for editing. I feel that show() and disable() are kind of cancelling each other out? What's the best approach to achieve this? Is there some kind of 'chain of command' to be considered?
editor.dependent('status', function (val, data, callback, e) {
editor.field('status').processing(false);
if (val == 'storno') {
editor.field('status').processing(true);
// First check if booking already has a stornocost value in booking_details
var currentStornocost = 0;
if (data.values.booking_details && data.row.booking_details.stornocost) {
currentStornocost = parseFloat(data.values.booking_details.stornocost) || 0;
}
// If stornocost already exists, use it directly
if (currentStornocost > 0) {
editor.field('stornocost').show();
editor.field('stornocost').val(currentStornocost);
editor.field('stornocost').disable(); // Make read-only since it's from stored data
editor.field('status').processing(false);
} else {
// Otherwise, calculate it from server
$.ajax({
url: datatablesajax.url,
type: 'POST',
data: {
action: 'getstornocost',
data: data.values,
},
dataType: 'json',
success: function (responseData) {
editor.field('stornocost').show();
editor.field('stornocost').val(responseData.values.stornocost);
editor.field('stornocost').enable(); // Allow editing of calculated values
}
});
}
}
});
Answers
ah... one has to correctly call the data

this is now working:
Thanks for the update. Good to hear you have it working now
Allan