This commit is contained in:
Aritra Banik 2024-02-25 12:26:09 +05:30
parent b341fe93ed
commit 430bcbc0ca
4 changed files with 49 additions and 13 deletions

BIN
src/a3

Binary file not shown.

View File

@ -186,11 +186,11 @@ import
products: seq[Products]
productCount = 0
countryError = ""
firstNameError = ""
lastNameError = ""
addressError = ""
stateError = ""
zipError = ""
# firstNameError = ""
# lastNameError = ""
# addressError = ""
# stateError = ""
# zipError = ""
emailError = ""
phoneError = ""
ch = ""
@ -260,8 +260,8 @@ import
zipError = ""
emailError = ""
phoneError = ""
passwordError = ""
ch = ""
# passwordError = ""
# ch = ""
echo "hi"
echo ctx.urlForm
echo "bye"
@ -401,7 +401,6 @@ import
"/validation/state" -> post:
var state = ctx.urlForm["c_state_country"]
echo state
var val: Validity
if state == "":
val.message = "State is Required"
@ -411,6 +410,18 @@ import
val.class = "text-success"
ctx.send sendState(state, val)
"/validation/zip" -> post:
var zip = ctx.urlForm["c_postal_zip"]
echo zip
var val: Validity
if zip == "":
val.message = "Zip is Required"
val.class = "text-danger"
else:
val.message = ""
val.class = "text-success"
ctx.send sendZip(zip, val)
"/contact" -> get:
var

View File

@ -165,10 +165,18 @@
name="c_state_country"
>
</div>
<div class="col-md-6">
<div
class="col-md-6"
hx-target="this"
hx-swap="outerHTML"
>
<label for="c_postal_zip" class="text-black">Posta / Zip <span class="text-danger">*</span></label>
<label class="text-danger">{{zipError}}</label>
<input type="text" class="form-control" id="c_postal_zip" name="c_postal_zip">
{# <label class="text-danger">{{zipError}}</label> #}
<input type="text" class="form-control" id="c_postal_zip"
hx-post="/validation/zip"
name="c_postal_zip"
>
</div>
</div>

View File

@ -66,10 +66,27 @@ proc sendState*(state: string, input: Validity): string =
>
<label for="c_state" class="text-black">State <span class="text-danger">*</span></label>
<label class="{input.class}">{input.message}</label>
<input type="text" class="form-control" id="c_state"
<input type="text" class="form-control" id="c_state_country"
hx-post="/validation/state"
name="c_state"
name="c_state_country"
value="{state}"
>
</div>
"""
proc sendZip*(zip: string, input: Validity): string =
result = fmt"""
<div
class="col-md-6"
hx-target="this"
hx-swap="outerHTML"
>
<label for="c_zip" class="text-black">Posta / Zip <span class="text-danger">*</span></label>
<label class="{input.class}">{input.message}</label>
<input type="text" class="form-control" id="c_postal_zip"
hx-post="/validation/zip"
name="c_postal_zip"
value="{zip}"
>
</div>
"""