From f9f4f408228c5dd41aa7bc7c9cfba48e829c9603 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 30 Mar 2020 13:53:24 +0530 Subject: [PATCH] Refactor InputDialog. Disallow empty input. --- components/InputDialog.js | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/components/InputDialog.js b/components/InputDialog.js index 1900fca..efce212 100644 --- a/components/InputDialog.js +++ b/components/InputDialog.js @@ -9,6 +9,26 @@ import { export default function InputDialog({ visible, onOK, onDismiss, title, label, placeholder }) { const [ text, setText ] = useState(""); + const [ error, setError ] = useState(false); + + function onChangeText(text) { + setText(text); + setError(text === ""); + } + + function onCancel() { + onDismiss(); + setText(""); + } + + function onDone() { + if (text === "") { + setError(true); + return; + } + onOK(text); + setText(""); + } return ( setText(text)} + onChangeText={onChangeText} mode="outlined" + error={error} /> - - + +