For different reason, sometimes is needed to restrict the number the user could select. I would like to know if there is some way to achieve it now.
thank you

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kansaj’s picture

I mean the number of items

infojunkie’s picture

Right now there isn't. We can keep this as a feature request, although I doubt I'll get to it soon.

kansaj’s picture

thank you for the prompt answer ! Hope to keep as request for new feature no matter the time horizon .
cheers

afly’s picture

i think it would be great if vbo can restrict the number to only one and convert checkbox into radiobutton then act as a table select widget .

kansaj’s picture

the radio button should be according to me new feature too, but the selector is a terrific feature, which provides much of flexibility and opportunities :)

dealancer’s picture

subscribing.

dealancer’s picture

Status: Active » Patch (to be ported)
FileSize
3.74 KB

Hi guys. I've made a patch. Now you could limit amount of selected check-box to one only. There is some php code that does validation and some jquery that unchecks checkboxes.

infojunkie’s picture

Status: Patch (to be ported) » Needs work

Re #7: Thanks for your patch. However, I would prefer having a general-purpose setting in the VBO style settings to determine how many items can be selected (min, max). Then the JS code and form validation code can check on those numbers.

dealancer’s picture

Yeah, there is setting in VBO style: checkbox. Next time I will try to add min and max fields.

infojunkie’s picture

Version: 6.x-3.x-dev » 6.x-1.x-dev
infojunkie’s picture

Please submit patches against 6.x-1.x-dev as VBO 6.x-1.10-beta2 and above support both Views 2.x and 3.x.

k4ml’s picture

I've also come to a situation where I need to limit the selection to 1, merely making it more like a radio button. For now, this js would just uncheck all the checkboxes except for one being checked:-

(function ($) {
Drupal.behaviors.vbo_unchecked = function(context) {
    $("#views-bulk-operations-form--1 input:checkbox").change(function() {
        if ($(this).is(':checked')) {
            $("#views-bulk-operations-form--1 input:checkbox").not(this)
                .removeAttr('checked')
                .parents("tr").removeClass('selected');
        }
    });
}
})(jQuery);

I did this before I found this issue and the patch in #7.

Miguel.Andrade’s picture

FileSize
3.18 KB

Hi,

This is a great feature. I actually just need the "select only one" version. I use it with rulesets so I can let users select some content and then run an action on it, but in most cases makes no sense to select more than one.

The proposed patch #7 did not applied completely on version = "6.x-1.10" so here's a new one.

dafeder’s picture

I'm trying to solve this problem in D7... I think a radio button option is very valuable for many use cases. I'm working on a patch that would add an option to the vbo config for "force single" and use radio buttons instead of checkboxes. I'm not sure it would be back-portable because it relies on views 3's views_form api.

infojunkie’s picture

I can't accept the patch in #13. To limit selection to just one item, the view should render radio buttons, not checkboxes.

For a truly general solution, here's what should happen:
* Allow admin to specify min and max count of items - provide special case option of 1 item with radio buttons
* On the view page, show those numbers in a themable way
* On the view page, show the number of currently selected items in a themable way
* On the view page, restrict selection to given range
* Validate submission

dafeder’s picture

Here is my initial patch for radio buttons, using a "force single" option in the vbo options. I don't know how easy this would be to backport to D6.

EDIT: Please disregard and use patch in #17

dafeder’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev
FileSize
7.01 KB

Sorry, number of problems with that patch. Please disregard and use this updated one.

bojanz’s picture

-    if (isset($info['base table']) && isset($data[$info['base table']])) {
+    if (isset($data[$info['base table']])) {

You're reverting a notice fix I made.

+        $form[$this->options['id']][$row_id] = array(
+          '#type' => 'radio',
+          '#parents' => array('views_bulk_operations'),
+          '#return_value' => $entity_id,
+        );    

'#parents' should be set to array($this->options['id']), you have no guarantee that the views field will always be called "views_bulk_operations'

Other than that, patch looks ready.
7.x can get the "range" functionality another day. The "force single" option is nifty enough. I love it how easy views_form makes this.

dafeder’s picture

Whoops, that revert was not intentional, I upgraded the module before committing my changes locally and ended up with a bunch of reverts like that in the patch. Thought I had corrected them.

Do you need me to submit a new patch?

bojanz’s picture

Nah, I can make the change before commit.

bojanz’s picture

Version: 7.x-3.x-dev » 6.x-1.x-dev
FileSize
6.19 KB

Improved the patch a bit and committed it.
Returning the issue back to infojunkie.

For reference, attaching the patch that I committed.
Rereading it shows me how fond I've become of empty() even when not needed. Fixed that in a followup:
http://drupalcode.org/project/views_bulk_operations.git/commitdiff/4e8de...

bojanz’s picture

Version: 6.x-1.x-dev » 7.x-3.x-dev
Status: Needs work » Closed (fixed)

6.x-1.x is feature frozen at this point.