When there's an error on the form, a version loads without compact forms.

Simple fix: move processing to pre_render callback so it's called each time the form is rendered.

Patch attached.

Comments

mark.’s picture

When you say "a version loads without compact forms," do you mean the page loads with the user's last entered text stuck behind the compact form label, and clicking the compact label does not make it fade out as its supposed to?

sun’s picture

I'd also like to know more about this. The code/patch looks valid.

NickWebman’s picture

nice patch! I so needed this!

I received the following when patching (and mind you, I know very little when it comes to command line anything)...

-bash-3.2$ patch < compact_forms_pre_render.patch
patching file compact_forms.module
Hunk #1 succeeded at 42 with fuzz 1.
Hunk #2 FAILED at 69.
Hunk #3 succeeded at 93 (offset 12 lines).
1 out of 3 hunks FAILED -- saving rejects to file compact_forms.module.rej

Although it seems to work wonderfully.

Thanks again,
Nick

nedjo’s picture

Status: Needs review » Needs work

Patch needs updating.

What I mean is that, in preview mode, there is no compact forms behaviour--forms are in their regular, non-compact format.

NickWebman’s picture

Status: Needs work » Needs review
StatusFileSize
new22.86 KB

zywiec: the OP is saying that when a form submission fails (ie. when a required field is not filled out) compact forms no longer takes effect. See attached image for example. After a failed attempt, the labels appear spaced wonkily, and they no longer fade in/out on focus/blur. This patch resolves the issue at hand.

ac’s picture

This patch works on the 7.x version of the module but throws a notice:

Notice: Undefined variable: form_id in compact_forms_pre_render() (line 78 of sites/all/modules/compact_forms/compact_forms.module).

Any chance of updating for 7.x and commiting? As it is compact forms is unusable.

Anonymous’s picture

This is still an issue in the 7.x branch, and the batch now fails per post #3. Anyway we can clean this up? Certainly makes compact_forms about unusable, as any input error causes the module to fail.

Edit: I typed 6, meant 7.

The patch does work, but it throws the error from #6. I'm going to see if I can figure it out and post my results.

Edit 2:

Line 55:
static $css_ids, $form_ids, $loaded, $field_size, $descriptions;

adding $form_id to this list seemed to clean up the error. The module still works great. Mine now looks like:

static $css_ids, $form_ids, $loaded, $field_size, $descriptions, $form_id;

cristhian’s picture

Absolutely agree with #7!

sun’s picture

Status: Needs review » Patch (to be ported)
StatusFileSize
new1.36 KB

Thanks for reporting, reviewing, and testing! Committed attached patch to 7.x-1.x.

A new development snapshot will be available within the next 12 hours. This improvement will be available in the next official release.

The proper fix for D7 would be to use #attached instead, but I don't have time to work on that right now, and this quick stop-gap fix is valid, too (although less performant).

JvE’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Needs review
StatusFileSize
new5.94 KB

For D7:
- moving code back to form_alter
- using #attached rather than _compact_forms_include_js in prerender
- using hook_element_info_alter() to process the elements

Christophe Bourgois’s picture

Issue summary: View changes

Using the compact_forms 7.x-1.0 I am facing the same problem.

Looking to different scripts I didn't find the one for my version.

So here is the solution working for me :

In the compact_forms_form_alter function, replace the lines

    // Load our page requisites and JavaScript settings.
    if (!isset($loaded)) {
      _compact_forms_include_js($css_ids);
      $loaded = TRUE;
    }

by the lines

    // Load our page requisites and JavaScript settings.
    if (!isset($loaded)) {
      _compact_forms_include_js($css_ids, $form);
      $loaded = TRUE;
    }

Then replace the _compact_forms_include_js function by

/**
 * Include JavaScript and CSS and attach behaviors to all selected forms.
 *
 * @param $css_ids
 *   An array containing CSS form ids.
 */
function _compact_forms_include_js($css_ids, &$form) {
  $path = drupal_get_path('module', 'compact_forms');
  $form['#attached']['js'][] = $path . '/compact_forms.js';
  $form['#attached']['css'][] = $path . '/compact_forms.css';

  $settings = array(
    'compactForms' => array(
      'forms' => $css_ids,
      'stars' => (int) variable_get('compact_forms_stars', 2),
    ),
  );
  $form['#attached']['js'][] = array(
    'type' => 'setting',
    'data' => $settings,
  );
}
mfrosch’s picture

Stumbled about the same.
For me I had to add another form id in compact forms configuration
On failure submit form id switched from article-node-form to article-node-form--2