I have the Input below using React Native.
<View style={ styles.container }>
<Input
placeholder="Add new chat"
value={input}
onChangeText={(text) => setInput(text)}
leftIcon={
<Icon name="wechat" type="antdesign" size={24} color="black" />
}
/>
<Pressable style={styles.buttonAdd} onPress={createChat}>
<Text style={styles.text}>Create</Text>
</Pressable>
</View>
If i type nothing then i get my alert which is fine however if i put 1 or + spaces the data gets submited. How can i disallow the submit and so set the alert when there is only spaces?
const [input, setInput] = useState("");
const createChat = async () => {
if(!input) {
alert("The chat name cannot be blank");
return;
}
await db
.collection("chats")
.add({
chatName: input
})
.then(() => {
navigation.goBack();
})
.catch(() => {
alert(error);
})
};