Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shadcn’s picture

barraponto’s picture

Status: Active » Needs review
FileSize
5.17 KB

This adds an implementation of `theme_input_group` and `theme_input_group_addon` to better support Bootstrap input groups (http://getbootstrap.com/components/#input-groups). It might need more of an effort if we want to support input-group checkboxes and radio controls and buttons.

Since I didn't find a use case for those, I didn't implement them. But text format is here :)

shadcn’s picture

I like this idea. But I'm dunno if input format is the best place to use this. It is looking a bit weird with the dropdown.

barraponto’s picture

Issue summary: View changes
FileSize
13.14 KB

Firefox and Chrome in my Arch Linux running Gnome... it looks like this.

bootstrapped text format

barraponto’s picture

barraponto’s picture

FileSize
4.24 KB
dsnopek’s picture

Status: Needs review » Needs work

Some quick review of the patch:

  1. +++ b/includes/form.inc
    @@ -80,6 +84,34 @@ function _radix_process_input(&$element, &$form_state) {
    +  $format['#theme_wrappers'] = array_map(
    +    function($function) {
    +      // Overrides only form_element wrapper.
    +      if ($function == 'form_element') {
    +        return 'input_group';
    +      }
    +      // But leaves the other wrappers in place.
    +      else {
    +        return $function;
    +      }
    +    },
    +    $format['#theme_wrappers']);
    

    This bit of code will only work on PHP 5.3 or greater.

    While most people are probably on PHP 5.3 or greater, Drupal 7 officially supports 5.2.5 or greater. So, either this bit of code will need to be changed OR we need to add 'php = 5.3' to the radix.info file.

  2. +++ b/includes/theme.inc
    @@ -33,6 +33,14 @@ function radix_theme(&$existing, $type, $theme, $path) {
    +    'input_group' => array(
    +      'render element' => 'element',
    +    ),
    +    'input_group_addon' => array(
    +      'variables' => array(
    +        'content' => NULL,
    +      ),
    +    )
    

    I think these should be called 'radix_input_group' and 'radix_input_group_addon' to match the other theme functions declared uniquely by Radix (and not from some other module).

dsnopek’s picture

Assigned: Unassigned » dsnopek
Issue summary: View changes
FileSize
4.84 KB
3.43 KB

Here's a new patch that addresses my review from above. Also, I noticed that this patch has a negative accessibility impact from this bit of code:

+++ b/includes/form.inc
@@ -80,6 +84,34 @@ function _radix_process_input(&$element, &$form_state) {
+  // Set title to show as a field_prefix if there is no field_prefix set.
+  $format['#field_prefix'] = empty($format['#field_prefix']) ?
+    $format['#title'] : $format['#field_prefix'];
+  unset($format['#title']);

This removes the label and it's relationship to the input.

Assigning this to me - I'm going to hack on this for a bit and see if I can fix this!

dsnopek’s picture

Assigned: dsnopek » Unassigned
Status: Needs work » Needs review
FileSize
5.14 KB
2.21 KB

Alright, here is a patch that addresses the accessibility issue by allowing you specify '#title_display' => 'input-group-before' and it'll put the title label into the input group. This requires a minor style change in compass_radix to remove the margin from labels inside .input-group-addon's:

https://github.com/arshad/compass_radix/pull/17

However, this approach makes me wonder if we shouldn't bake support for input groups right into radix_form_element()? We could add a '#input_group' => TRUE that would render the prefix/suffix into a Bootstrap input group, and support the same '#title_display' => 'input-group-before' / 'input-group-after' that's in my patch? That way, we can easily turn any form element into an input group but WITHOUT losing any of the functionality of radix_form_element() (which does more stuff than theme_radix_input_group()).

Anyway, not sure if that makes sense...

dsnopek’s picture

FileSize
5.91 KB

Here's a re-roll of this patch for the latest 7.x-3.x, including the changes that used to be in the PR against the compass gem. This is untested, but I'll get to that soon!

My question about approach #9 is still relevant (I'll think about that again after I test this), but the functionality itself is pretty sound - I've been using it with client sites for over a year.

dsnopek’s picture

Status: Needs review » Needs work

It worked in my testing with latest 7.x-3.x! Marking as "Needs work" to deal with #9

dsnopek’s picture

Status: Needs work » Needs review
FileSize
6.31 KB
5.31 KB

Ok, here's a new version of the patch that addresses the question (from myself) in #9.

Rather than providing a new theme wrapper that you can swap in, it integrates the changes directly into radix_form_element(). It allows you to do something like:

$form['amount'] = array(
  '#type' => 'textfield',
  '#title' => t('Amount'),
  '#field_prefix' => '$',
  '#field_suffix' => '.00',
  // Non-standard attribute which causes it to use a Bootstrap input group.
  '#input_group' => TRUE,
);

As you can see, there's now '#input_group' => TRUE which will cause it to use a Bootstrap input group for the '#field_prefix' and '#field_suffix'.

Then it also adds some non-standard values for the '#title_display' attribute: 'prefix' and 'suffix', which will basically put the title into the '#field_prefix' or '#field_suffix' respectively.

Used together, you can make a Bootstrap input group which has the field title as the prefix, which we use on the text format selector!

Anyway, the effect is the same, but I'm much happier with this patch than the original. :-) But it could still use some more testing and review!

dsnopek’s picture

FileSize
4.88 KB
1.73 KB

The last patch had some left-over code from the old approach that's no longer necessary! Here's an updated patch that just removes that code, that isn't even used anyway in the new approach. So, smaller patch, same effect!

shadcn’s picture

David, if all good here, please go ahead and commit this one as well. Thanks.

  • dsnopek committed 2c4dd2f on 7.x-3.x
    Issue #2223365 by dsnopek, barraponto: Use input group component for...
dsnopek’s picture

Status: Needs review » Fixed

Yeah, all my code concerns are now addressed and this has been working in my testing for a couple weeks now. So, committed! :-)

Status: Fixed » Closed (fixed)

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