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

View File

@ -165,10 +165,18 @@
name="c_state_country" name="c_state_country"
> >
</div> </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 for="c_postal_zip" class="text-black">Posta / Zip <span class="text-danger">*</span></label>
<label class="text-danger">{{zipError}}</label> {# <label class="text-danger">{{zipError}}</label> #}
<input type="text" class="form-control" id="c_postal_zip" name="c_postal_zip"> <input type="text" class="form-control" id="c_postal_zip"
hx-post="/validation/zip"
name="c_postal_zip"
>
</div> </div>
</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 for="c_state" class="text-black">State <span class="text-danger">*</span></label>
<label class="{input.class}">{input.message}</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" hx-post="/validation/state"
name="c_state" name="c_state_country"
value="{state}" value="{state}"
> >
</div> </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>
""" """