I'd like to allow form element default values to be set from amp-state
. Currently amp-bind
operates on user interaction so initial state state (eg [selected]
) can't be set from an amp-state
. An example use case would be allowing the amp-state
injected by amp-geo
(or loaded from a CORS endpoint) to set a default currency on an ecommerce site.
cc @choumx @cramforce
Sorry it took so long to respond to this.
This somewhat bends the semantics of amp-bind not executing on page load. Plus, there would be a race between form submission and amp-bind
initialization (unless we chose not to override user selection, which is even more bendy).
IMO we should use a different mechanism for interaction between amp-form and amp-geo.
Just noticed a Stack Overflow question I think is the same issue. https://stackoverflow.com/questions/56882857/amp-state-getting-ignored-until-setstate-fired
<amp-geo>
provides useful functionality we are asking applications to re-implement server side to initialize the initial values for pages not served from an AMP cache. But it seems impossible to do if served from the AMP cache. Geo data seems to need computation on first page load. Almost like need to be able to trigger a geo event on page load (e.g. an attribute of amp-geo?) to cause amp-state to be updated once the geo is known. That is, amp-geo seems a special case here? Is there any other way to get the AMP cache to initialize the attributes correctly based on geo?
Feels like this may be a case that the best solution is to be able to initialize in the browser on page load so the AMP cache can store the same page for everyone?
Most helpful comment
Just noticed a Stack Overflow question I think is the same issue. https://stackoverflow.com/questions/56882857/amp-state-getting-ignored-until-setstate-fired
<amp-geo>
provides useful functionality we are asking applications to re-implement server side to initialize the initial values for pages not served from an AMP cache. But it seems impossible to do if served from the AMP cache. Geo data seems to need computation on first page load. Almost like need to be able to trigger a geo event on page load (e.g. an attribute of amp-geo?) to cause amp-state to be updated once the geo is known. That is, amp-geo seems a special case here? Is there any other way to get the AMP cache to initialize the attributes correctly based on geo?Feels like this may be a case that the best solution is to be able to initialize in the browser on page load so the AMP cache can store the same page for everyone?