Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Check For Empty Input Values


import * as React from 'react';
import {useState, useRef} from 'react';
import { View, Text, TouchableOpacity, TextInput, StyleSheet, SafeAreaView, Button } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import SelectDropdown from 'react-native-select-dropdown'


function HomeScreen({navigation}) { 

const [value, setValue] = useState("");
const countries = ["Egypt", "Canada", "Australia", "Ireland"]
 
 const checkTextInput = () => {
  //Check for the Name TextInput
  if (!value.trim()) {
    alert('Please Enter Name');
    return;
  } 
  //Checked Successfully
  //Do whatever you want
  alert('Success');
  navigation.navigate("Details", {value:value})
};

  
  return (
    <SafeAreaView style={{flex: 1}}>
    <SelectDropdown
	data={countries}
  defaultValue={value}
	onSelect={(selectedItem, index) => {
setValue(selectedItem);
  }}
	buttonTextAfterSelection={(selectedItem, index) => {
		// text represented after item is selected
		// if data array is an array of objects then return selectedItem.property to render after item is selected
		return selectedItem
	}}
	rowTextForSelection={(item, index) => {
		// text represented for each item in dropdown
		// if data array is an array of objects then return item.property to represent item in dropdown
		return item
	}}
/>
<TouchableOpacity onPress={()=>
checkTextInput()
}>
<Text>
  Click Me To Go To Details
</Text>

</TouchableOpacity>
    </SafeAreaView>
  );
}



const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 35,
  },
  textInputStyle: {
    width: '100%',
    height: 40,
    paddingHorizontal: 5,
    borderWidth: 0.5,
    marginTop: 15,
  },
});



function DetailsScreen({route}) {
 const {value} =route.params;

  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Details Screen</Text>
   <Text>{value}</Text>

    </View>
  );
}


const Stack = createNativeStackNavigator();

function App() {
  return (
    <NavigationContainer>
    <Stack.Navigator initialRouteName="Home">

      <Stack.Screen name="Home" component={HomeScreen} />

    <Stack.Screen name="Details" component={DetailsScreen} />
    </Stack.Navigator>
  </NavigationContainer>
  )
}

export default App;
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Check #For #Empty #Input #Values
ADD COMMENT
Topic
Name
4+8 =