It would be great to be able to select an entity by clicking anywhere in its row, like you can in views bulk operations or even in a standard list field. Right now, you have to click on the tiny check box which can be difficult for some users. In VBO, selecting anywhere in the row checks the box, and in a standard list field, you can select the label text.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pizzabrarian created an issue. See original summary.

aolaze’s picture

I want to use it in VBO form.
I search the form api ,now.
How can i do?

TD44’s picture

+1
jwineichen , how did you do ?

jwineichen’s picture

FileSize
120.48 KB

There is a checkbox in the view's bulk operations field settings. I've attached a screenshot showing where it is for me.
*edit* I guess my highlight didn't show up. It's the "make the whole row clickable" checkbox.

TD44’s picture

I was talking about make the whole row clickable in the entity reference view .
Did you use a VBO view as Entity Reference View?

jwineichen’s picture

Ah, I misunderstood. I'm not a programmer so I haven't gotten it to work. I'm still hoping for someone who has skills to reply to the feature request.

westerish’s picture

Found one way to achieve this with a little jquery borrowed from the VBO module...

(function ($) {
  // Polyfill for jQuery less than 1.6.
  if (typeof $.fn.prop != 'function') {
    jQuery.fn.extend({
      prop: jQuery.fn.attr
    });
  }

  Drupal.behaviors.wes = {
    attach: function(context) {
      $('.view-target-environments', context).each(function() {
        Drupal.wes.initTableBehaviors(this);
        Drupal.wes.initGenericBehaviors(this);
        Drupal.wes.toggleButtonsState(this);
      });
    }
  }

  Drupal.wes = Drupal.wes || {};
  Drupal.wes.initTableBehaviors = function(form) {
      $('.views-table tbody tr', form).click(function(event) {
        if (event.target.tagName.toLowerCase() != 'input' && event.target.tagName.toLowerCase() != 'a') {
          $('input[id^="edit-entityreference-view-widget"]:not(:disabled)', this).each(function() {
            var checked = this.checked;
            // trigger() toggles the checkmark *after* the event is set,
            // whereas manually clicking the checkbox toggles it *beforehand*.
            // that's why we manually set the checkmark first, then trigger the
            // event (so that listeners get notified), then re-set the checkmark
            // which the trigger will have toggled. yuck!
            this.checked = !checked;
            $(this).trigger('click');
            this.checked = !checked;
          });
        }

    	});
    }
})(jQuery);

Lifting and repointing the row select method from vbo tables to entity reference views widget tables. Name of the behaviours was formerly Drupal.vbo renamed to Drupal.wes to avoid conflicts.

Imagine there's probably a better method that requires less duplication but this was a simple way to bolt on in my case.

You'll want to modify this selector .view-target-environments to your view's name/class, or make it more generic (eg .checkrow) generic and then make sure that class is added to your view(s) where you want it to perform.
$('.view-target-environments', context).each(function() {

brunodbo’s picture

Thanks for the snippet in #7! Works for me as well, with one change: when I tried it first, I selected the outermost view element (I added a specific class to the .view element and looked for that in the JS). This worked for selecting table rows initially, but not after filtering the view (using exposed filters). I changed the JS to select .views-form instead, like VBO does, and then selecting rows worked also after filtering. I also changed the .views-form class to .evw-views-form to be more specific (again, like VBO does).

Samvel’s picture

In modal done, please review

jsacksick’s picture

Status: Needs review » Fixed

Patch looks good, just tested it, added a cursor:pointer to the table rows to make it clearer and committed it, thanks!

Status: Fixed » Needs review
  • jsacksick committed 02aa77d on 7.x-2.x authored by Samvel
    Issue #2801381 by Samvel, jsacksick: Add ability to select anywhere in...
Samvel’s picture

It looks like ticket haven't status fixed and then credit not provided.

jsacksick’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.