The title says it all, if you have a cck text field with multiple values, _rubik_filter_form_alter breaks the filter-form and the javascript for dragging the cck-items. I disabled _rubik_filter_form_alter completely to get a working form again.

cheers,

Stephan

Comments

stijndm’s picture

I was able to break this down to three issues:

  1. Drag and Drop is broken
  2. Filter radio's aren't themed correctly
  3. When having unlimited fields: after adding another the filter options are themed as a fieldset again

1. Drag and Drop is broken

This is due to the following piece of code which ignores Drag and Drop weight elements:

$form = array(
  '#type' => 'item',
  '#weight' => isset($form['#weight']) ? $form['#weight'] : 0,
  $form
);

Changing this to the following fixes the problem, although this is just a quick fix. The point is to check for the Drag and Drop weight element before doing stuff:

if (isset($form['_weight'])) {
  $weight = $form['_weight'];
  unset($form['_weight']);
  
  $form = array(
    '#type' => 'item',
    '_weight' => $weight,
    $form
  );
}
else {
  $form = array(
    '#type' => 'item',
    '#weight' => isset($form['#weight']) ? $form['#weight'] : 0,
    $form
  );  
}

2. Filter radio's aren't themed correctly

This is a problem with the css not being applied correctly to filter options in a multiple field.
More specifically, these selector under Form description exceptions are causing the style issues:

.page-content table .form-item,
.page-content table .form-item .description,

If you want a quick solution you could replace

/* Filter form */
.filter-options .form-item,
.filter-options .filter-help {
  font-size:11px;
  margin:10px 10px 0px 0px;
  padding:0px;
  float:left;
  }

  .filter-options .form-item:hover > .description { display:none; }

with

/* Filter form */
.page-content table .filter-options .form-item,
.filter-options .form-item,
.filter-options .filter-help {
  font-size:11px;
  margin:10px 10px 0px 0px;
  padding:0px;
  float:left;
  }

  .page-content table .filter-options .form-item .description { display:none; }
  .filter-options .form-item:hover > .description { display:none; }

3. When having unlimited fields: after adding another the filter options are themed as a fieldset again

This is to do with the theme that processes the Add Another not being run through rubik_preprocess_form_filter().
No solution here yet.

karens’s picture

Status: Active » Needs review

I ran into this too. I think basically Rubik should just leave the filter form alone when it is in a CCK unlimited value field. I tried added a check for that before altering the filter and it leaves the other filters alone and just skips the ones that are problematic.

I don't have a cvs version of the code loaded so I can do a proper patch, but I altered the code to look like this:

function _rubik_filter_form_alter(&$form) {
  $found = FALSE;
  $fields = $form['#fields'];
  foreach (element_children($form) as $id) {
    // Filter form element found
    if (
      isset($form[$id]['#element_validate']) &&
      is_array($form[$id]['#element_validate']) &&
      in_array('filter_form_validate', $form[$id]['#element_validate'])
    ) {
      // Unlimited value CCK fields should not be altered
      // to avoid breaking the AHAH drag n drop and 'Add more'
      // functionality.
      if (isset($form['#field_name'])) {
        $field_name = $form['#field_name'];
        $field = content_fields($field_name);
        if ($field['multiple'] == 1) {
          continue;
        }
      }
      $form[$id]['#type'] = 'markup';
      $form[$id]['#theme'] = 'filter_form';
      $found = TRUE;
    }
    // Formatting guidelines element found
    elseif ($id == 'format' && !empty($form[$id]['format']['guidelines'])) {
      $form[$id]['#theme'] = 'filter_form';
      $found = TRUE;
    }
    // Recurse down other elements
    else {
      _rubik_filter_form_alter($form[$id]);
    }
  }
  // If filter elements found, adjust parent element.
  if ($found) {
    foreach (element_children($form) as $element) {
      $form[$element]['#rubik_filter_form'] = TRUE;
    }
    $form = array(
      '#type' => 'item',
      '#weight' => isset($form['#weight']) ? $form['#weight'] : 0,
      $form
    );
  }
}
karens’s picture

That might be cleaned up by moving the test to where _rubik_filter_form_alter() is called and just bypass this function altogether if this is a multiple value field.

markdorison’s picture

StatusFileSize
new1017 bytes

Rolled KarenS's changes into a patch.

nicholas.alipaz’s picture

patch seems pretty good to me, except I still see an issue if I have a cck flexifield, set to multiple values, that contains a text field (filtered input).

my_flexifield (unlimited)
- input (filtered)

jaydub’s picture

StatusFileSize
new1016 bytes

The patch in #4 will only work when the CCK field in question is set to 'unlimited' values in which case $field['multiple'] is equal to 1. If the number of values for the field in question is 2 or more then the value of $field['multiple'] is equal to the number of values.

So the revised patch simply tests for whether $field['multiple'] is greater than 0.

jaydub’s picture

StatusFileSize
new1.34 KB

I re-rolled my patch in #6 to account for an additional scenario. We are using the Better Formats module and in the case where you have a CCK field with multiple values set AND using Better Formats you only have 1 format able to be used for a given field/user, the patch in #6 doesn't help. So I've altered the patch to protect against the issue with the form alter breaking AHAH drag 'n' drop for this additional scenario.

mrconnerton’s picture

I have applied and tested #6 and works for me. I didn't use #7 simply because I don't have better formats.

nicholas.alipaz’s picture

This still doesn't seem to fix issue with flexifield although other field types look good.

alduya’s picture

The patch in #7 solved the issue for me. But it does generate a whole lot of these:
notice: Undefined index: #fields in /Users/alduya/Sites/testing/sites/all/themes/rubik/template.php on line 604.
And line 604:

<?php
$fields = $form['#fields'];
?>

doesn't seem to be necessary. $fields is not used in that function.

sammys’s picture

StatusFileSize
new1.23 KB

Here's #7 with the #10 line removed. Works fine and even resolved a problem where some of the values in a multiple value textarea field were removed. Weird behaviour.

+1 for the commit.

dsnopek’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #11 works great for me!

haydeniv’s picture

Status: Reviewed & tested by the community » Fixed

Committed: 3623bbb
Thanks!

Status: Fixed » Closed (fixed)

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