I'm trying to make a validation for my dropdown, where if the user chose a value that is already chosen the app should prompt a modal for the validation.
I have 2 arrays, first tagsData that I use to display the tags in my dropdown, second is slidesDetails which is a param from a different screen/page that I use to check if there's a tag that is already chosen.
Then I use for loop and if else to iterate through the arrays and check if the tags of dropdown is already chosen, if yes, then modal should prompt for the user validation. And if the tag is not yet chosen, the app should navigate to another screen and display those tags in a Flatlist.
Base on console.log, it is detecting where and when the tags is matching. The problem is, it is keeping on looping and then navigating to another screen regardless of the condition.
Note: My Flatlist is detecting if there is a tag with the same Key that is why I seriously need to accomplish my validation.
const tagsData = [
{ id: '1', label: 'Store Schedule', tagValue: "Store Schedule" },
{ id: '2', label: 'Substandard Items', tagValue: "Substandard Items" },
{ id: '3', label: 'Promo Display', tagValue: "Promo Display" },
{ id: '4', label: 'Rack Display', tagValue: "Rack Display" },
{ id: '5', label: 'Chiller Display', tagValue: "Chiller Display" },
{ id: '6', label: 'Freezer', tagValue: "Freezer Display" }
];
const openCam = async () => {
tagsData.map(async (item) => {
slidesDetails.map(async (elements) => {
// console.log("_____updatedSlides: ", updatedSlides);
var I_tagValue = item.tagValue;
var E_tagValue = elements.tagValue;
console.log("_____tagsValue_Data: ", E_tagValue);
for (let i = 0; i < E_tagValue.length; i++) {
console.log("_____I_tagValue: ", I_tagValue);
if (I_tagValue !== E_tagValue) {
console.log("_____tagItem: ", E_tagValue);
console.log("Continue");
setSlideDetails(updatedSlides);
await AsyncStorage.setItem('tagKey', JSON.stringify(updatedSlides))
navigation.dispatch(
StackActions.replace("Deck_Report", {
*** route.params ***
})
);
break;
} else {
console.log("Match items")
return (
<SafeAreaView>
<Modal visible={true}>
<SafeAreaView style={[styles.fill, styles.grey]}>
<Button title='Hide' onPress={hideModal} />
</SafeAreaView>
</Modal>
</SafeAreaView>
)
}
break;
}
})
})
}