Lightbox should be able to open after form submission with data from server.
What's the issue?
AMP-Lightbox should have multiple layout options instead of being forced to use "layout=nodisplay". This will allow custom error messages to be returned from the server inside of a lightbox component.
How do we reproduce the issue?
We are trying to implement various error messages for failed POST requests and relying on on="submit-success...;submit-error:... does not offer us the necessary flexibility (can only have 1, generic error message for non-200 responses this way).
We are instead relying on the below approach to dynamically return JSON from the server:
<form>
<div submit-success>
<template type="amp-mustache">
....
</template>
</div>
<div submit-error>
<template type="amp-mustache">
....
</template>
<div>
</form>
Because these div elements are naturally hidden inside the form element, the Lightbox Component should not rely on user-interaction to be displayed (as this is already handled by the form submission). The current flow of AMP form submission will not allow us to call the submit-error method alongside a submit-error html div (AMP does not believe my-lightbox exists when called by the function):
on="submit-error: my-lightbox
<div submit-error>
<template type="amp-mustache">
<amp-lightbox id="atc-error-modal" layout="nodisplay">
<div class="lightbox error-lightbox">
<div id="atc-error-modal-content" class=" border px3 pt1 relative left-align">
<span id="close-atc-error" class="absolute center z4 " on="tap:atc-error-modal.close" role="button" tabindex="0">X</span>
<p class="h1 my0 red" >{{title}}</p>
<p class="h6 my1 nowrap">{{errorMsg}}</p>
<p class="h6 my0">{{contact}}</p>
</div>
</div>
</amp-lightbox>
</template>
<div>
Perhaps supporting layout="container" or layout="fill" might solve this problem?
@bthomas16 the error is because my-lightbox and the id of the lightbox id="atc-error-modal" are different. They need to be the same. Please give that a try and if does not work, let us know. I agree we should support your use-case of opening a dialog with dynamic data on submission. layout is not the solution for it however. The code you have is the right approach and if it does not work, we can make it work.
Thank you for the reply aghassemi.
The above code was just for sample purposes, and I am indeed calling on="submit-error: atc-error-modal"
However I kept receiving the error that my atc-modal does not work with the proper code in place Target "atc-error-modal" not found for action [submit-error:atc-error-modal].
The workaround I have found also has its own set of problems: Wrapping amp-lightbox around
<amp-lightbox id="atc-error-modal" layout="nodisplay">
<div submit-error>
<template type="amp-mustache"
....
</template>
</div>
</amp-lightbox>
But AMP-validation errors say div cannot have attribute submit-error. This is because submit-error & submit-success must be direct children of amp-form.
Currently I am at a loss and am considering creating my own version of amp-lightbox with CSS and toggleVisibility()
Thanks @bthomas16
/to @cvializ to investigate and prioritize.
This issue hasn't been updated in awhile. @cvializ Do you have any updates?
It looks like the expected behavior in the report is the current behavior.
https://ampb.in/#5LXvtW4hAMz96WIWLwkU
<form method="get"
action="https://httpbin.org/response-headers?AMP-Access-Control-Allow-Source-Origin=https%3A%2F%2Fampb.in&access-control-expose-headers=AMP-Access-Control-Allow-Source-Origin"
action-xhr="https://httpbin.org/response-headers?AMP-Access-Control-Allow-Source-Origin=https%3A%2F%2Fampb.in&access-control-expose-headers=AMP-Access-Control-Allow-Source-Origin"
target="_blank"
on="submit-success:test-lightbox;">
<fieldset>
<label>
<span>Your name</span>
<input type="text" name="name" id="name" required>
</label>
<label>
<span>Your email</span>
<input type="email" name="email" id="email" required>
</label>
<input name="submit-button" type="submit" value="Subscribe">
</fieldset>
<div submit-success>
<template type="amp-mustache">
Success! Thanks {{name}} for submitting! Please make sure to check your email {{email}}
to confirm!
<amp-lightbox id="test-lightbox" class="lightbox" layout="nodisplay">
<div class="lightbox-content">
Thank you {{name}} for submitting the form. Check your email {{email}}. Wow!
</div>
</amp-lightbox>
</template>
</div>
<div submit-error>
<template type="amp-mustache">
Oops! {{name}}, We apologies something went wrong. Please try again later.
</template>
</div>
</form>
I'll close this issue, and if the expected behavior fails again we can reopen.