Home › Forums › Bug Reports › Range field broken when using decimals
Trying to use the wonderful new Range slider to go from 0 to 1 in increments of 0.01 (hundreths), but when I do I get an the validation error “Validation failed. Please enter a valid value. The two nearest valid values are 0 and 1.”
Here’s some screenshots…
Settings:
Field:
Error on page save:
Trying increments of .1 (tenths) doesn’t work either, and it doesn’t seem to matter if I write it as .1 or 0.1 (with leading zero).
Thanks!
I can confirm that this is happening, but I cannot confirm if this is a bug or expected behavior. Please submit a support ticket so that it can be brought to the attention of the developer. https://support.advancedcustomfields.com/new-ticket/
I’ve submitted a ticket and will update this post with their response.
Seems like it shouldvalidate, at least according to the <input type=range> spec. Per https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range:
By default, the granularity, is 1, meaning that the value is always an integer. You can change the step attribute to control the granularity. For example, If you need a value between 5 and 10, accurate to two decimal places, you should set the value of step to 0.01
Hi guys
Thanks for the bug report.
I’ve just replicated the issue and believe to have found the problem.
The issue is not with the range input, but the number input beside it.
I need to add the ‘step’ attribute to this element also, otherwise, it performs HTML number validation. I’ll have this fixed in the next version.
For now, please edit the file ‘includes/fields/class-acf-field-range.php’ on line 101 and change to:
$html .= acf_get_text_input(array(
'type' => 'number',
'id' => $atts['id'] . '-alt',
'value' => $atts['value'],
'step' => $atts['step']
));
That fixes it, thank you! Look forward to it in the next update.
The topic ‘Range field broken when using decimals’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.