Change @jashkenas/inputs value from click event in Leaflet map?

I am attempting to update the value of a @jashkenas/inputs text form using a value derived from a click event in a Leaflet map. The idea here is that a user could either provide the coordinates manually or from clicking on a map.

I am able to get the value I need from the click event, but I am having trouble passing it into the text form. The text form value is apparently a constant. As such it appear I cannot just assign the value from the click event to the variable containing the initial text form value. Iā€™ve included a basic example of what Iā€™ve been trying to. Does anyone have any suggestions for how I can pass the value from a click event into a @jashkenas/inputs text form?

Hereā€™s something that works:

(I think I learned this trick from the Linked Inputs example.)

The ā€œassigning to a constantā€ error occurs because Observable cells are in strict mode, and inside the cell newCoordinates hasnā€™t been defined yet. You donā€™t actually need a new view cell for what youā€™re trying to do, so I just placed the code defining the event handler directly inside the map cell.

Thereā€™s also a fancier technique in Synchronized Views that Iā€™ve also used from time-to-time.

1 Like

This is great. There are a few concepts I think I need to dig into a bit more, but this approach on the whole makes sense. Thanks for the suggestions and explanation!

1 Like

Specifically for Jeremyā€™s inputs collection thereā€™s also

which automatically handles most of the widgets.

2 Likes

@mootari ā€” Is Mutable Forms a feature that youā€™d like (and think would be appropriate) to merge back into the Inputs notebook?

It seems generally useful, and safe ā€” as long as we keep it in mind when adding any new input types.

@jashkenas Iā€™d love to, but right now Iā€™m getting a 500 server error when I try to fork the changes that I added.

Edit: It worked after I reloaded the original notebook and reapplied the changes.