I am trying to rewrite our stack to be AMP valid
I have the following pattern :
- A search bar is available to type in a query.
- When you type text (input-debounce), an amp-list is shown (unhidden) and a new state variable searchQuery is created with the content of event.value (the search bar input value)
- A call is made to endpoint A by an amp-state component (with searchQuery as a parameter)
- The results are displayed in the amp-list as links with some text content (let's call it title) and a blank href (#)
Now what I would like is that when you click a result from the list, the value of the search input be set the value of the clicked element. Like an autocomplete/selector of some sort.
What I tried is having an on attribute on each list item with
tap:AMP.setState({searchQuery: event.value})
But when I click a result, the search bar value is always set to null.
I tried : event.value event.target.value event.innerHTML event.innerContent event.text
Also tried replacing the link (a) to a span a button and such, same result.
Is this actually possible with AMP ?
You have to bind the
inputelement's value tosearchQueryfor this to work. Here is a simplified sample (without an amp-list):