Conditional Options on Editor Field
Conditional Options on Editor Field
wolphitdepartment
Posts: 6Questions: 2Answers: 0
Hello. How would I the options for select dependent on a field's value?
`
(function($){
$(document).ready(function() {
var myEditor = new $.fn.dataTable.Editor( {
serverSide: true,
ajax: 'myphpfile.php',
table: '#my_table',=
fields: [
{
"label": "Status",
"name": "mytable.status",
"type": "select",
"options": [
if (mytable.status=="OKAY") {
{ label: "A", value: "A" },
{ label: "B", value: "B" },
}
else if (mytable.status="NOT OKAY)") {
{ label: "C", value: "C" },
{ label: "D", value: "D" },
}
]
}
]
} );
`
Answers
Use
dependent()
. It provides a way to give a function that can be used to update the Editor form whenever required (e.g. on start edit, create, etc). There is an example available here.Allan
The example on the link you sent is only for hiding/showing editor fields. How do I make this code work to where dependent() API can be used to populate options for a SELECT field?
dependant()
's return value can include anoptions
parameter, or you could callfield().update()
directly on the field in question:Allan
Thank you for your response. It's working. However, I'm using AJAX and upon update, I'm getting this error:
I tried to fool around using this code but I don't know where to put the code you provide inside this code here:
I can see that error be displayed if the ajax call doesn't succeed - the callback is only being called in the
success()
function. Are you seeing errors in the browser's console, or any errors in the server-side logs?Colin
The condition is working but there's a DTE_Processing_Indicator in the modal and when I checked the browser console after clicking the update button, it shows that field is still processing error.
We'd need a link to your page showing the issue to be able to debug the problem. The code above looks correct.
Allan