Support

Account

Home Forums Bug Reports Unable to save empty value in range field

Solving

Unable to save empty value in range field

  • Number range field with no required value should be able to save (and load !) empty value.

  • What are the other settings for the field? Min/Max/Step?

    What do you mean by no value?

    I’m not seeing any validation errors when I save a range field, but this would depend on all of the field settings.

  • Hello,

    Min: -50
    Max: 50
    Step: 5
    Required: no
    Default value: empty

    There’s no validation error, but since I don’t set any default value and field is not required, I assume that when field is empty, it should NOT be treated as field with explicit 0 value.
    That’s what I need to distinguish.

    For now, when submitting article, the empty range fields get 0 value.

  • It appears that ACF sets the value to 0 if it is empty, this includes the first time it is updated. It then adjusts this up or down. If the min is > 0 it get’s set to min. If the max is < 0 it’s set to max. So, it appears that a range field can never be empty.

  • Did some more digging. It appears that if you remove the value that is added, for example 0. If you remove the value, whatever it is and the field is blank, the field value get’s set to mid range, whatever that might be. I cannot find anything in ACF code that causes this behavior. I believe that this is the correct operation of a range field as explained here https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/range

  • I understand. So the only way to do so is by adding a boolean field just before and condition range field visibility on it.

    Thanks John for your answers

  • Heh, I got to learn something.

    1) I thought is was a number field powered by JS and didn’t know that browsers had actually added support for a range field, probably another nightmare to style if I use it on a client site, like the file field.

    2) I understand how the field operates so if I use it I will not be surprised by this myself.

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

You must be logged in to reply to this topic.