Support

Account

Home Forums Bug Reports Range field broken when using decimals

Solved

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:
    Settings

    Field:
    Field

    Error on page save:
    Error

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Range field broken when using decimals’ is closed to new replies.