Is it possible to show/hide individual Editor checkboxes in a set?
Is it possible to show/hide individual Editor checkboxes in a set?
I suspect fields.className
and the events API can be used to show/hide sets of checkboxes, but can individual checkboxes within a set be attached to events?
As an example, say I am writing a log of various database events:
Enable / disable logging
--> Log row creation
----> Log creation time
----> Log user who created the row
----> Log SQL used to create the row
--> Log row deletion
----> Log delete time
----> Log user who deleted the row
----> Log SQL used to delete the row
I'd like to display these values in a logical, hierarchy in the Editor form:
If "Log row creation" is checked --> Show checkboxes for creation time, creation user, and SQL. indented from the "Log row creation" checkbox.
If "Log row creation" is unchecked --> hide those checkboxes, because they don't apply.
Is it practical to do this?
This question has an accepted answers - jump to answer
Answers
Yes, but you would need to attach your events "manually". For example you could use
field().input()
to get theinput
elements in a field (for a checkbox field you'd get a jQuery object that contains the checkbox inputs). They could then have events assigned to them using$().on()
.Having said that, in this particular case you might find it slightly easier to create a custom field type which will contain that logic internally. The field type would be specific to this one use case, but it does mean all the logic is contained and should make for slightly easier maintenance. It could also be useful if you want to control the value that is get / set.
Out of interest - why would you have input values for the log example you give? Would the value not be determined automatically from the actions on the data? You'd never go "I've just deleted that row - I better mark it as deleted"?
Allan
Thank you, Allan!
While more of a generic checkbox hierarchy question, the specific example is one of configuring how Editor works. Also, the formatting of my question was lost; many newlines are missing so it looks like one deep hierarchy rather than two wider hierarchies.
Given checkbox: "[X] Enable logging for delete events" (which might, even without other checkboxes, log some items such as the deletion date).
If checked, show the following dependent checkboxes:
Etc.
Without "Enable logging for delete events", the other three checkboxes are irrelevant.
"Enable logging for delete events" is itself irrelevant if "Enable logging of any kind" is not checked, ad practicum.
Got - it - thanks! Interesting use case.
I've fixed that now. In this flavour of markdown a double space is needed at the end of a line to keep the line break. I must update the markdown to fix that...
Allan