AMP4EMAIL: Setting Form Values from State in Templates

239 Views Asked by At

I'm seemingly unable to dynamically set a a form input field's value via the [value] attribute while using amp-bind within an amp-mustache template. This issue only occurs in the Gmail client. It works as expected within the Gmail Amp Playground and within the browser. This issue only occurs in the Gmail client. It works as expected within the Gmail Amp Playground (which I would assume should mirror the behavior of the Gmail client) and within the browser.

A gist is available here with a contrived version of the client side code.

Any suggestions / workarounds gratefully appreciated!

And while it's likely not needed, here's the server-side logic:

        public class TestRequestModel {
            public string TestId { get; set; }
        }
        private string ValidId = "correct";
        [HttpPost]
        public async Task<IActionResult> TestGetId([FromForm]AEGetRepresentativesRequestModel requestModel)
        {
            AddRequiredAmpHeaders();
            if (requestModel == null)
            {
                return BadRequest(new {});
            }
            return Ok(new TestRequestModel { TestId = ValidId });
        }
        [HttpPost]
        public async Task<IActionResult> TestUseId([FromForm]TestRequestModel requestModel)
        {
            AddRequiredAmpHeaders();
            if (requestModel == null)
            {
                return BadRequest(new {});
            }
            if (requestModel.TestId != ValidId)
            {
                return BadRequest(new { Error = $"Invaild id: {requestModel.TestId}" });
            }
            return Ok(new { TestId = ValidId });
        }
1

There are 1 best solutions below

1
On

Update: seems there's a second bug in Gmail that's still affecting this.

This was caused by a bug in Gmail that interfered with how event.response worked when it was used in combination with AMP.setState. I just checked and it seems to be fixed now, so your code should work.