fieldPlugin and .dependent()
fieldPlugin and .dependent()
Hi,
I wanted to achieve a toggle button on my form for lookup / manual entry of address data.
I successfully implemented the plugin featured here https://editor.datatables.net/examples/plug-ins/fieldPlugin.html
The toggle button works well.
However 'dependent' does not fire when I reference the plugin field.
editor.dependent( 'bLookupVsManual', function ( val ) {
console.log(val)
return {}
}, {
event: 'change'
} )
I have tried to do a manual change trigger within the plugin click event as follows:
editor.field( 'bLookupVsManual' ).input().trigger('change')
Is there a reason dependent does not work with the plugin?
My workaround is to place the editor.field().show() / editor.field().hide() into the click listener within the plugin code though I think naming specific fields is getting too specific for a plugin so I wondered if dependent could be made to work.
Thanks for any help.
Answers
Yes, that plug-in doesn't trigger an
input
event itself because it doesn't useinput
elements. Its a little bit of a cheat since it usesbutton
elements.The way to make
dependent()
work with it would be to trigger achange
event inside the click event listener.Allan
Thank you Allan, I rethought the problem and have created a much smoother flow using radio buttons, dependent and trigger.
My only issue with radios is styling. I want the radios to be presented in the 'datatables button style' ie class="inputButton". CSS is not my strong point so I did wonder if this has been done before.
I had implemented your useful suggestion to make radios in the horizontal here: https://datatables.net/forums/discussion/39132/custom-field-type-for-horizontal-radio-buttons
I would like to achieve a horizontal toggle button styling as shown in the plugin:
https://editor.datatables.net/examples/plug-ins/fieldPlugin.html
Is this possible with radios?
Any help greatly appreciated
Hi Allan,
I have solved the problem! The CSS solution for a button-formatted toggle using radio buttons with a flexbox is below, I hope it might help others.