briancwald / material_admin

Drupal 8 Admin Theme
GNU General Public License v2.0
48 stars 15 forks source link

add empty label if no label comes through in forms API #12

Closed briancwald closed 7 years ago

briancwald commented 7 years ago

Materializecss requires a label for it to transform the checkbox correctly. If It comes through forms API and no label is present, you just won't see the checkbox at all. This adds a blank label if there is none to avoid checkboxes not showing up.

For examples, Features_ui module does not provide a label (for some reason?) to download an archive of the feature. without this update, you see no checkbox.

briancwald commented 7 years ago

I'm realizing this is also an issue if a module uses a checkbox that is NOT getting the forms API wrapper (and no label) (I.E. Hardcoded checkboxes). I guess I will need a method to add labels to those too. Ideas on how to handle this?

Features UI ALSO does this for the bulk selection checkbox.

e0ipso commented 7 years ago

Ideas on how to handle this?

Maybe in that case you get the default browser checkbox, as an incentive to use Form API? I think that a Drupal theme should be safe to assume the use of Form API for form elements.

mortenson commented 7 years ago

The only other alternative I can think of, for hard-coded checkboxes, is to use JS after page load to append empty labels.

briancwald commented 7 years ago

yeah I could try something like this, but its pretty nasty...

        if(this.sibling.nodeName != 'label') {
          $(this).after('<label for="'+this.id+'"></label>')
        }
      })
briancwald commented 7 years ago

This method doesnt seem to cause weird behavior or 'duplicate' checkboxes in various areas so I dont think this solution works.

briancwald commented 7 years ago

Another case of this coming up, this time in core: https://www.drupal.org/node/2897139

I think I can address the ones coming from FormAPI because I added a 'no-label' if it doesnt have anything in the container.

title_display not in ['after', 'before'] ? 'form-no-label',