I have come up with a rude hack to make Webform References show a tree for a lot of checkboxes:
In webform_references.term.inc
function _webform_references_get_term_list($vid, $sort_by = 'name', $order = 'ASC', $tree = TRUE) {
Changing $tree to TRUE, because the calling function (line 284) never sends this argument,
then in a custom site module:
function custommodule_form_alter(&$form, $form_state, $form_id) { if($form_id ==="webform_client_form_1512" || $form_id ==="webform_client_form_1486"){ //these form_ids correspond to your webforms ids // this small hack gives us a nice tree structure in the webform when using checkboxes // the checkbox children MUST have a dash at the front of their label // which requires line 584 of webform_references.term.inc to be added to: $tree = TRUE; $form['#attached']['js'] = array( backdrop_get_path('module', 'custommodule') . '/custommodule_webform.js', ); } }
and the javascript file custommodule_webform.js:
console.log("webform modifier at custommodule_webform.js."); $(function(){ $("label.option").each(function(){ var $this = $(this); if($this.text().charAt( 0 ) =='-'){ $this.parents('div.checkbox').css("margin-left", "20px"); $this.attr("class", "option child"); var text=$this.text(); var result = text.substring(1, text.length); $this.text(result); } }); });
The above javascript iterates over the labels in the checkboxes, finds those with the hyphen at front ( the children ), applies inline styling to bump it along 20px, add a child class to the label incase of styling needs and then remove the hyphen from the innerText of the label.
Save, enable module, clear cache, test your webforms.
Of course, if the module gets updated, and this is not accounted for, the hack will need to be reapplied!
@argiepiano : is there any reason why the calling of the function _webform_references_get_term_list does not have the $tree set to true, that you can see?
@onyx, thanks for this post. I'm not a maintainer of webform references - you will need to post in their issue queue to ask.
Somewhat related: there are a couple of issues for Backdrop core that will add indentations to taxonomy term tree core widgets (when using radios or checkboxes). This is made possible by another issue that adds indentations to core form elements. These two will probably be added in the next version of Backdrop.
It'd be great to ask the Webform References maintainer to add this functionality to the webform term reference widget as well.