editor.dependent on checkbox
editor.dependent on checkbox
redbaron
Posts: 12Questions: 6Answers: 1
I am unable to get the events a field of type checkbox. I am using a standalone form, and it does work for a field of type select.
Here is a snip of the code. I know that my return function is wrong, but I am having an issue with the event not being called at all when using field 'securityAccessLevels'.
$(document).ready(function () {
editor = new $.fn.dataTable.Editor({
ajax: "{{ baseUrl }}/admin/UserMaintenance?cmd=ajax",
table: "#Users",
idSrc: "id",
fields: [{
label: "User Name:",
name: "username"
}, {
label: "e-Mail:",
name: "emailAddr"
}, {
label: "Password:",
name: "password"
}, {
label: "Enabled:",
name: "valid",
type: "select"
}, {
label: "Access:",
name: "securityAccessLevels",
type: "checkbox"
}, {
label: "Contractor Selection:",
name: "generalContractors",
type: "select"
}, {
label: "Manager Selection:",
name: "projectManagers",
type: "select"
}
]
});
editor.dependent('securityAccessLevels', function ( val, obj, callback ) {
var arrHide = [];
var arrShow = [];
if ( isInArray(5, val) )
{
arrShow.push("generalContractors");
} else {
arrHide.push("generalContractors");
}
if ( isInArray( 2, val) )
{
arrShow.push("projectManagers");
} else {
arrHide.push("projectManagers");
}
return { hide: arrHide, show: arrShow};
} );
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
It is somehow related to the data I am loading from Ajax, as when I put the values in manually it works.
,
My guess is that the field does not exist yet when I am trying to attach an event.
This field that has the checkboxes is having the data loaded in the following manner:
{"data":<<<SNIP>>>
,"options":{"valid":[{"label":"Yes","value":1},{"label":"No","value":0}],
"securityAccessLevels":[{"label":"Manager","value":"1"},{"label":"Manager - Supervisor","value":"2"},{"label":"Trains","value":"3"},{"label":"Subs","value":"4"},{"label":"Contractor","value":"5"},{"label":"Division","value":"6"}]
Are you able to give me a link to the page so I can take a look and try to debug it directly please?
Thanks,
Allan
Thanks Allan. I sent you a pm with the links
Hi,
I'm also interested in this subject :)
Vladimir
I have the code on a server that demonstrates the problem, available here:
http://phdev2.dev.redbaron.bz/testing
The first form shows the working functionality, using static text.
The second form on that page shows the inability to load ajax data on a secondary table.
form2.php shows the same table with Ajax data, not working.
Thanks for the test case @redbaron. The issue is in how Editor is attaching the event listeners for Ajax loaded data. It uses
$().on()
without a delegated listener, so it can only listen to thechange
event for the elements it finds whendependent()
is executed.Since your options are Ajax loaded, there are no checkboxes in the form at that point - hence the error here.
As a workaround you can use the
dependent()
method insideinitComplete
and that will allow it to work as expected.I'll look into how this can be fixed for the 1.5.6 release and will post back here when its done.
Regards,
Allan
Yes, initComplete did the work, but when I tried to save data into MySql I've received this error:
<b>Notice</b>: Array to string conversion in <b>/editor/Database/Driver/Mysql
/Query.php</b> on line <b>93</b><br />
Regards,
Vladimir
Solution for this problem is to use Mjoin because this is one-to-many join.
Just a quick update on this. I've implemented a fix and it will be in the 1.5.6 release which should be out soon. The workaround will continue to work just fine as well.
Allan