I don't know if this should be posted here or under Taxonomy Super Select -- let me know if I should move it.

I'm trying to use Taxonomy Limit with Taxonomy Super Select, since I would like to use checkboxes instead of a multi-select list, and I would like to limit the number of categories selected. However, when I try to submit an event with Taxonomy Super Select enabled, Taxonomy Limit insists I have too many categories selected, regardless of how many have been checked.

Taxonomy Limit works fine when Taxonomy Super Select is disabled, and vice versa.

Comments

alfaguru’s picture

I have a fix for this issue which I've performed some very basic testing on. The problem arises because when TSS is used the array of values tested includes the unchecked terms (values set to zero) as well as checked ones. This module currently counts the total number of entries rather than only non-zero ones.

Fortunately there is a simple fix, to pass the array through the array_filter function before counting the entries. When this function is used without a callback it removes all entries equal to FALSE, which in this case are the ones for the unchecked terms. So changing line 98 of the module from:

				if (sizeof($edit['taxonomy'][$vid]) > $max) {

to:

				if (sizeof(array_filter($edit['taxonomy'][$vid])) > $max) {

does the trick. (I would supply this as a patch except that my setup doesn't make it very easy to do so. )

mvc’s picture

Version: 5.x-1.2 » 6.x-0.1
Assigned: Unassigned » mvc
Status: Active » Fixed

This particular bug is now fixed in the Drupal 6 release.

There are a bewildering number of taxonomy related modules available, many of which conflict with each other. It may not always be possible to change taxonomy limit to work with them all, especially in combination. However, on the grounds that being more lenient with user input was better I have applied a similar patch to what alfaguru suggested.

Status: Fixed » Closed (fixed)

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

natuk’s picture

Status: Closed (fixed) » Active

I am afraid this is not working for me in version 6.x-0.1.

I believe these are the lines responsible:

    // Non freetagging vocabulary
    // (taxonomy super select sets the values to FALSE, instead of removing
    // them from the array, so we filter out these values)
    if (is_array($form['taxonomy'][$vid]['#value']) &&
        sizeof(array_filter($form['taxonomy'][$vid]['#value'])) > $max) {
      form_set_error("taxonomy][$vid", $error);
    }

I am not quite sure what is happening here, but the last one does not seem right.

detot’s picture

doesn't work for me either, any solution?

rabielmo’s picture

I was able to go around the situation in the _taxonomy_limit_validate_max_terms() function in taxonomy_limit.module, by modifying the lines pointed out by naku in #4 above. Here is the array that actually contains the tags being tested:

    // Non freetagging vocabulary
    // (taxonomy super select sets the values to FALSE, instead of removing
    // them from the array, so we filter out these values)
    if (is_array($form['nid']['#post']['taxonomy'][$vid]) &&
        sizeof(array_filter($form['nid']['#post']['taxonomy'][$vid])) > $max) {
      form_set_error("taxonomy][$vid", $error);
    }

Let me know if this works for anyone else.

valariems’s picture

Thank you, rabielmo (#6). The patch worked for me.

rickdrup’s picture

Patch at #6 worked perfectly for me also. I'm running Taxonomy Limit, Taxonomy Super Select & Taxonomy Role on Drupal 6. Thanks.

mvc’s picture

Status: Active » Fixed

I've (finally) tagged a stable version for D6, which includes the patch from #6. Thanks.

mvc’s picture

Version: 6.x-0.1 » 6.x-1.0

Status: Fixed » Closed (fixed)

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