Comments

greenavus’s picture

Same here. I would like the select list title to be shown instead of none.

Jarviss’s picture

StatusFileSize
new3.08 KB

Labels inside compact select lists. Works fine with Drupal 7.10, Drupal 7.12
Best to see it included in Compact forms 7, because now it makes labels inside any Select List,
in compact forms there is a way to provide ID of forms to apply compact forms!

Jarviss’s picture

StatusFileSize
new3.02 KB

+ Views 7.x-3.1 select filters works fine

johnv’s picture

Title: Need Select List to appear with labels inside whithout NONE » Support for Select lists (without NONE)
Status: Active » Needs review
StatusFileSize
new1.49 KB

This is nice!
I created this as a patch (SVN-style, since no D7-git provided yet), So I can include it in the current module.

Some first remarks?
- It works for all forms, so not only for the activated forms by ComactForms?
- The textfields have italic labels, Select lists not.

But perhaps it works better on its own?

johnv’s picture

StatusFileSize
new1.75 KB

Here is my modificated module. I got errors with range fields like Date.

wbobeirne’s picture

StatusFileSize
new1.39 KB

Attaching a patch that fixes an error that pops up if the #language index is not set on a form.

grasmash’s picture

Adding a git patch. This is rolled against the git repo.

Also, I've added an option on the admin settings page so that "compact select lists" can be enabled or disabled.

I've modified the code a significant amount in the interest of improving readability, which is a Drupal coding standards priority.

This patch should be tested against various types of forms and form elements.

grasmash’s picture

Status: Needs review » Needs work

Just realized that the patch actually modifies all forms, not just those specified for compact forms. Going to update.

grasmash’s picture

Status: Needs work » Needs review

Ok, updated patch. I had to move some code around to create a new compact_forms_check_form_id() function, which is now shared by the pre_render handler and the select element handlers.

I'm still not sure that this is an ideal patch-- I worked off of the code that was contributed earlier in this thread. However, I think that this should ideally use compact_forms_pre_render() to perform all form modifications, rather than implementing additional hooks. I'll consider refactoring again.

grasmash’s picture

forgot to attach!

grasmash’s picture

Alright-- massively simplified. This method mimics the original functionality. Only one issue with the patch at the moment-- no 'required' star is being appended to the select list form element when "Leave star after the label" is set.

grasmash’s picture

Alright, that's enough for me. Here's a patch that takes care of the asterisk.

I'm not sure what the preferred functionality would be. You could append an asterisk after the selected option by modifying compact_forms.js, e.g.:

      if (stars === 0) {
        $label.find('.form-required').hide();
      }
      else if (stars === 1 && $field.is('select')) {
        $label.find('.form-required').appendTo($field.find('option[value="_none"]')).prepend(' ');
      }
      else if (stars === 2) {
        $label.find('.form-required').insertAfter($field).prepend(' ');
      }

However, I'm pretty sure that placing a <span> within an <option> is invalid HTML. So I went with adding a simple asterisk:

       if (stars === 0) {
        $label.find('.form-required').hide();
      }
      else if (stars === 1 && $field.is('select') && $label.find('.form-required').length) {
        $field.find('option[value="_none"]').append(' *');
      }
      else if (stars === 2) {
        $label.find('.form-required').insertAfter($field).prepend('&nbsp;');
      }
johnv’s picture

Status: Needs review » Needs work

I implemented #12.
1. for every select list , the following message appears: "Notice: Undefined index: #title in _compact_forms_resize_fields() (line 139 of ..\compact_forms.module)."
2. the title of each select list just disappears.
3. Support for Views Exposed Forms is lost as of #11, since hook_form_views_exposed_form_alter() is not included anymore.
4. I find the following this a bit awkward. Did you somewhere switch the meaning of $desctiptions ?

@@ -128,7 +145,7 @@ function _compact_forms_resize_fields(&$form, $field_size, $descriptions) {
         if (!empty($field_size)) {
           $form[$key]['#size'] = $field_size;
         }
-        if (!$descriptions) {
+        if ($descriptions) {
           unset($form[$key]['#description']);
         }
 
johnv’s picture

Also, these classes stil lneed to be added to the changed label/first option:

$label.parent().addClass('compact-form-wrapper');
$label.addClass('compact-form-label');
$field.addClass('compact-form-field');

attiks’s picture

Status: Needs work » Needs review
StatusFileSize
new4.33 KB

Alternative approach using only javascript

jelle_s’s picture

Issue summary: View changes
StatusFileSize
new4.85 KB

Patch in combination with patch from #669878: Support for HTML5 placeholder attribute

weinewmode’s picture

a simplified patch to the latest version (revision: 0890d60e, branch: 7.x-1.x).