From 31179d729249b69f935a92bea34c649bf7aa0377 Mon Sep 17 00:00:00 2001 From: KeviNmp4 Date: Sun, 12 May 2024 22:59:15 +0200 Subject: [PATCH] Fixes: #15 --- frontend/app/(app)/(tabs)/beer/add.js | 36 +++++++++++++++++---------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/frontend/app/(app)/(tabs)/beer/add.js b/frontend/app/(app)/(tabs)/beer/add.js index 367cc75..71a444b 100644 --- a/frontend/app/(app)/(tabs)/beer/add.js +++ b/frontend/app/(app)/(tabs)/beer/add.js @@ -11,13 +11,11 @@ const DropdownTheme = require("@components/DropdownTheme"); export default function BeerAdd() { const [b_name, setBName] = useState(""); const [b_degree, setBDegree] = useState(""); - const [b_packaging, setBPackaging] = useState(""); + const [b_packaging, setBPackaging] = useState(null); const [b_brand, setBBrand] = useState(""); const [image, setImage] = useState(null); - const [selectPackaging, setSelectedPackaging] = useState(); const [open, setOpen] = useState(false); - const [value, setValue] = useState(null); const [items, setItems] = useState([ { label: "Tank beer", value: "tank" }, { label: "Cask beer", value: "cask" }, @@ -74,6 +72,22 @@ export default function BeerAdd() { } }; + function validateDegreeInput(text) { + let newText = ""; + let numbers = "0123456789."; + + for (var i = 0; i < text.length; i++) { + if (numbers.indexOf(text[i]) > -1) { + newText = newText + text[i]; + setBDegree(newText); + } else { + // your call back function + alert("Please enter numbers only."); + setBDegree(""); + } + } + } + async function addBeer() { // TODO: after the request - redirect to /beer/{new_beer_id}?; plus some modal about successful state const req = await fetch(`${process.env.EXPO_PUBLIC_API_URL}/beer/add`, { @@ -123,25 +137,21 @@ export default function BeerAdd() { style={styles.input} placeholder="Degree" value={b_degree} - onChangeText={(text) => setBDegree(text)} - placeholderTextColor="#aaaaaa" - /> - setBPackaging(text)} + onChangeText={(text) => validateDegreeInput(text)} placeholderTextColor="#aaaaaa" + keyboardType="numeric" /> +