From 121dba686fc9ace4496dcbbb9c32fe9a6d40531a Mon Sep 17 00:00:00 2001 From: libexi01 Date: Thu, 4 Jul 2024 14:38:00 +0530 Subject: [PATCH] 47 --- src/htmx.v | 22 ++++++++++++++++++++++ src/services.v | 2 +- src/templates/signup.html | 33 +++++++++++++++++++++++++-------- src/view.v | 15 +++++++++++++++ 4 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/htmx.v diff --git a/src/htmx.v b/src/htmx.v new file mode 100644 index 0000000..92438fc --- /dev/null +++ b/src/htmx.v @@ -0,0 +1,22 @@ +module main + +pub struct HTMX { +mut: + name string + message string + mark string +} + +fn htmx_get_username(input HTMX) string { + return ' +
+ + +
' +} \ No newline at end of file diff --git a/src/services.v b/src/services.v index bb8807f..1475540 100644 --- a/src/services.v +++ b/src/services.v @@ -6,7 +6,7 @@ fn (mut app App) service_add_user(username string, email string, password string if username == '' || email == '' || password == '' { return error('Invalid input') } - + mut db := databases.create_db_connection()! defer { diff --git a/src/templates/signup.html b/src/templates/signup.html index 5c1fc6d..4873205 100644 --- a/src/templates/signup.html +++ b/src/templates/signup.html @@ -3,23 +3,40 @@ Sign Up - @css 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css' + @css 'https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.css' + + @js 'https://unpkg.com/htmx.org@2.0.0'

Create an Account

-
- - +
+ +
-
+
- +
-
+
- +
diff --git a/src/view.v b/src/view.v index 7982995..3eac682 100644 --- a/src/view.v +++ b/src/view.v @@ -4,4 +4,19 @@ import vweb pub fn (mut app App) signup() vweb.Result{ return $vweb.html() +} + +@['/htmx/username'; post] +pub fn (mut app App) htmx_username(username string) vweb.Result{ + mut htmx := HTMX{ + name: username, + message: "", + mark: "" + } + if username == '' { + htmx.message = "username cannot be empty" + htmx.mark = 'style="border: 2px solid #e74c3c;"' + return app.text(htmx_get_username(htmx)) + } + return app.text(htmx_get_username(htmx)) } \ No newline at end of file