mirror of
https://github.com/bigskysoftware/htmx.git
synced 2025-10-02 15:25:26 +00:00
Fix the inline validation example by using a post request
This commit is contained in:
parent
6d85d1ae5b
commit
12fcc51124
@ -15,7 +15,7 @@ We start with this form:
|
|||||||
<form hx-post="/contact">
|
<form hx-post="/contact">
|
||||||
<div hx-target="this" hx-swap="outerHTML">
|
<div hx-target="this" hx-swap="outerHTML">
|
||||||
<label>Email Address</label>
|
<label>Email Address</label>
|
||||||
<input name="email" hx-get="/contact/email" hx-indicator="#ind">
|
<input name="email" hx-post="/contact/email" hx-indicator="#ind">
|
||||||
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -94,7 +94,7 @@ Below is a working demo of this example. The only email that will be accepted i
|
|||||||
return formTemplate();
|
return formTemplate();
|
||||||
});
|
});
|
||||||
|
|
||||||
onGet(/\/contact\/email.*/, function(request, params){
|
onPost(/\/contact\/email.*/, function(request, params){
|
||||||
var email = params['email'];
|
var email = params['email'];
|
||||||
if(!/\S+@\S+\.\S+/.test(email)) {
|
if(!/\S+@\S+\.\S+/.test(email)) {
|
||||||
return emailInputTemplate(email, "Please enter a valid email address");
|
return emailInputTemplate(email, "Please enter a valid email address");
|
||||||
@ -115,7 +115,7 @@ Below is a working demo of this example. The only email that will be accepted i
|
|||||||
return `<form hx-post="/contact">
|
return `<form hx-post="/contact">
|
||||||
<div hx-target="this" hx-swap="outerHTML">
|
<div hx-target="this" hx-swap="outerHTML">
|
||||||
<label>Email Address</label>
|
<label>Email Address</label>
|
||||||
<input name="email" hx-get="/contact/email" hx-indicator="#ind">
|
<input name="email" hx-post="/contact/email" hx-indicator="#ind">
|
||||||
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@ -133,7 +133,7 @@ Below is a working demo of this example. The only email that will be accepted i
|
|||||||
function emailInputTemplate(val, errorMsg) {
|
function emailInputTemplate(val, errorMsg) {
|
||||||
return `<div hx-target="this" hx-swap="outerHTML" class="${errorMsg ? "error" : "valid"}">
|
return `<div hx-target="this" hx-swap="outerHTML" class="${errorMsg ? "error" : "valid"}">
|
||||||
<label>Email Address</label>
|
<label>Email Address</label>
|
||||||
<input name="email" hx-get="/contact/email" hx-indicator="#ind" value="${val}">
|
<input name="email" hx-post="/contact/email" hx-indicator="#ind" value="${val}">
|
||||||
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
<img id="ind" src="/img/bars.svg" class="htmx-indicator"/>
|
||||||
${errorMsg ? ("<div class='error-message'>" + errorMsg + "</div>") : ""}
|
${errorMsg ? ("<div class='error-message'>" + errorMsg + "</div>") : ""}
|
||||||
</div>`;
|
</div>`;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user