The Spectrum widget always shows the alpha slider - even when the "Record opacity" field option is not checked.

Comments

kasperg created an issue. See original summary.

kasperg’s picture

Title: Spectrum widget: Unable to hide alpha » Spectrum widget: Alpha slider does not respect Record opacity setting
kasperg’s picture

As far as I can tell the Spectrum library expects configurations to be boolean but Drupal stores these as strings ("1") or numeric values (0). This already seems to be addressed for one setting. The attached patch takes the same approach for the remaining settings.

I have also included a patch which applies to 8.x-2.0-rc1 for good measure.

kasperg’s picture

Status: Active » Needs review

The last submitted patch, 3: spectrum_widget_alpha-2760221-3.patch, failed testing.

gerzenstl’s picture

StatusFileSize
new1.78 KB

The issue that affects this option, is affecting also to the other ones like show palette, buttons, ...

The PHP values exposed for the spectrum widget are the following:

array (size=7)
  'palette' => string '' (length=0)
  'show_input' => string '0' (length=1)
  'show_palette' => string '0' (length=1)
  'show_palette_only' => string '0' (length=1)
  'show_buttons' => string '0' (length=1)
  'allow_empty' => string '0' (length=1)
  'show_alpha' => int 1

On Javascript, the double quotes operator works with integers like 0 or 1 but not with strings like "0" or "1".

The only scenario where you won't reproduce the issue is when you use the default values for this widget.

I made a port of the approach taken for the D7 version to solve the issue. I tested all options and all of them are working fine with this fix.

Status: Needs review » Needs work

The last submitted patch, 6: color_field_spectrum_widget-2760221-6.patch, failed testing.

gerzenstl’s picture

Assigned: Unassigned » gerzenstl
Status: Needs work » Needs review
gerzenstl’s picture

The CI error seems unrelated to the patch I submitted.

ERROR: No valid tests were specified.

casivaagustin’s picture

I have tested the patch and works well for me

gerzenstl’s picture

ping

gerzenstl’s picture

CI error is gone and patch is ready for review.

nickdickinsonwilde’s picture

Assigned: gerzenstl » Unassigned
Status: Needs review » Fixed

Since the other settings have already been fixed by other issues, mostly ditched the patch. Used the knowledge from that patch to use type casting for clearest/quickest code. Also, added a test. Thanks for the report and patch.

  • NickWilde committed 82568e5 on 8.x-2.x
    Issue #2760221 by kasperg, gerzenstl, casivaagustin, NickWilde: Spectrum...
nickdickinsonwilde’s picture

Status: Fixed » Closed (fixed)

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