Can you use a Generator or Promise as default value for an Input

I have an Astronomical clock notebook which recently stopped working.

All the sliders depend on either a generator or promise (respectively one that keeps the time if requested, and one that yields the current location). This stopped working recently. It turns out the sliders never yield a value until you drag them. These are the Sliders from @observablehq/inputs.

Or alternatively, is there a canonical way to set inputs to a value by default that you can only obtain asynchronously?

The problem isn’t promises; it’s the step option.

You’ve defined the observer_lat and observer_lon range inputs using step = 0.1; however, you’re setting the initial value of the range inputs to a value that does not match the specified step interval, and hence is considered invalid. Previously the range input would implicitly round an invalid value on assignment to the closest value according to the step, but in a recent release it was made more strict and ignores invalid values on assignment (which is what most inputs do).

A quick fix is to round the initial values to match the step, e.g. using number.toFixed (which technically returns a string, but it’ll get coerced back to a number immediately, so that seems fine):

value: default_position.lon.toFixed(1)

I’ve also filed this issue to track, since it wasn’t really my intention to change the behavior here and probably it’s desirable to have the implicit autocorrect for invalid values on range inputs.

1 Like

Thanks, that solves the problem.

The issue of overly-strict validation with range inputs has now been fixed.