Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sometimes the value of the opacity is something like 0.834, which has 5 characters, but on the form element definition in color_field_admin.inc this is what we have:
$element['opacity'] = array(
'#type' => 'textfield',
'#title' => t('Opacity'),
'#description' => t('Between 0 and 1'),
'#default_value' => $opacity,
'#size' => 4,
'#maxlength' => 4,
);
This leads to a error:
"Opacity cannot be longer than 4 characters but is currently 5 characters long."
Tweaking #size and #maxlength to 5 seems to fix the problem.
Comment | File | Size | Author |
---|---|---|---|
#11 | opacity_longer_than_4-2805163-11-D8.patch | 832 bytes | petermallett |
#10 | opacity_longer_than_4-2805163-10.patch | 951 bytes | gooddesignusa |
#2 | opacity_longer_than_4-2805163-2.patch | 472 bytes | ankur.addweb |
Comments
Comment #2
ankur.addweb CreditAttribution: ankur.addweb at AddWeb Solution Pvt. Ltd. commentedPFA patch.
Comment #4
ankur.addweb CreditAttribution: ankur.addweb at AddWeb Solution Pvt. Ltd. commentedCan anyone please review and let me know if that works for you all or not?
As the attached patch works for me well!
Comment #5
ron_s CreditAttribution: ron_s commentedOk... if you need a higher level of specificity, why not just hook the element and change it in code? There could be someone in the future who needs 6, or someone else who only wants 2, etc.
Comment #6
HLopes CreditAttribution: HLopes commented@ron_s: Even if patched, the approach you suggested (hook_form_alter) will still work. This issue happened with the Spectrum color picker library, which is mentioned in the module page. That's the only reason I've decided to create this ticket.
@darshi: the patch seems to work OK.
Comment #7
ron_s CreditAttribution: ron_s commented@HLopes, I'm using the Spectrum color picker too. As far as I can see, it always returns a maximum 4 character opacity value when using Color Field 2.x and the opacity slider. I've tested it maybe 100 times and never more than two decimal places.
What version of Spectrum are you using? I'm on the 1.8.0 release. Are you using the slider, or are you manually typing in an opacity value using the "Show Input" option?
Comment #8
HLopes CreditAttribution: HLopes commented@ron_s: happened with the slider, on 1.8 as well. But I'm not currently able to reproduce it, oddly enough...
Comment #9
ron_s CreditAttribution: ron_s commented@HLopes, one thing you might want to consider is trying this patch I created: https://www.drupal.org/node/2816291#comment-11722337
There is definitely a problem with the module's Spectrum JavaScript code for both the rgb and opacity values. There may have been a use case where incorrect values are being returned because of this problem.
Comment #10
gooddesignusa CreditAttribution: gooddesignusa commentedI ran into this issue as well. I ended up fixing it on the JS level. Just round the value to 2 places.
Comment #11
petermallett CreditAttribution: petermallett at Mediacurrent commentedWe're seeing the same issue in 8.x-2.x-dev. It seems the alpha value for the Spectrum widget does need to store up to 5 characters.
I created a D8 version of the first patch from this issue. The other option (limiting what the widget attempts to store to 4 char instead) seems fine, too but because the widget already truncates to max 5 char if you manually input more, this seemed like the right way to go.
Comment #12
NickDickinsonWildeAlready fixed - by changing the opacity field to a numeric field. The opacity on all fields widgets is limited to 100/ths for ease of use. If there is a rare case that someone needs more, they can use a form alter.