From cea4f35d521067624af99a3b6a2c9a746f25c4bf Mon Sep 17 00:00:00 2001 From: CheddarCrisp Date: Wed, 4 Mar 2020 20:53:18 -0500 Subject: [PATCH] Add validation to forms Fix values being treated as strings --- src/ncounter/App.svelte | 30 ++++++++++------- src/ncounter/Counter.svelte | 65 ++++++++++++++++++++++--------------- src/ncounter/site.css | 7 ++++ 3 files changed, 64 insertions(+), 38 deletions(-) diff --git a/src/ncounter/App.svelte b/src/ncounter/App.svelte index 42ffea1..84f6418 100644 --- a/src/ncounter/App.svelte +++ b/src/ncounter/App.svelte @@ -11,14 +11,16 @@ {#if showAddDialog}
-
- - - +
+ + + - - -
+
+ + +
+
{/if} {#if showAbout} @@ -32,6 +34,7 @@ import { counters } from './db.js'; let showAddDialog = false; let showAbout = false; let newCounter = null; +let dialogForm = null; function focus(node){ node.focus(); @@ -41,6 +44,7 @@ function showAdd(){ newCounter = { title: '', initialValue: 0, + max: '', saveHistory: false, history: [] } @@ -49,9 +53,15 @@ function showAdd(){ } function add(){ + if(!dialogForm.checkValidity()) { + dialogForm.removeAttribute('novalidate'); + return; + } + const counter = { ...newCounter, - value: newCounter.initialValue + max: newCounter.max !== '' ? +newCounter.max : null, + value: +newCounter.initialValue } counters.add(counter); @@ -60,10 +70,6 @@ function add(){ } \ No newline at end of file diff --git a/src/ncounter/site.css b/src/ncounter/site.css index 02bb4e1..397b497 100644 --- a/src/ncounter/site.css +++ b/src/ncounter/site.css @@ -125,6 +125,13 @@ button:focus, button:hover { width: auto; } +.dialog-content .buttons { + display: flex; + flex-direction: row-reverse; + justify-content: space-between; + width: 100%; +} + .dialog-content button:focus, .dialog-content button:hover { border: 0; outline: 2px solid var(--button-color);