Browse Source

fixing pre-selected items on forms

master
GabrielTrettel 4 years ago
parent
commit
8ad7b89ec7
  1. 20
      src/app/screens/RainSharingDataScreen.js
  2. 17
      src/app/screens/RiverFloodSharingDataScreen.js
  3. 24
      src/app/screens/SharingFloodZonesScreen.js

20
src/app/screens/RainSharingDataScreen.js

@ -15,13 +15,14 @@ import { scaleDimsFromWidth } from "../config/dimensions";
import assets from "../config/assets"; import assets from "../config/assets";
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
images: Yup.array().min(1, "Por favor, selecione ao menos uma imagem"),
images: Yup.array(),
}); });
const borderWidth = 4; const borderWidth = 4;
function RainSharingDataScreen(props) { function RainSharingDataScreen(props) {
const [rain, setRain] = useState(0);
const [rain, setRain] = useState(-1);
const [error, setError] = useState(false);
const location = useLocation(); const location = useLocation();
return ( return (
@ -43,6 +44,10 @@ function RainSharingDataScreen(props) {
images: [], images: [],
}} }}
onSubmit={(values) => { onSubmit={(values) => {
if (rain == -1) {
setError(true);
return;
}
insertRainData({ ...values, rain, location }); insertRainData({ ...values, rain, location });
showMessage({ showMessage({
message: "Informação enviada!", message: "Informação enviada!",
@ -138,6 +143,13 @@ function RainSharingDataScreen(props) {
</TouchableNativeFeedback> </TouchableNativeFeedback>
</View> </View>
</View> </View>
{error && rain == -1 && (
<Text style={styles.error_txt}>
Selecione se está passável ou não
</Text>
)}
<FormImagePicker backgroundColor={colors.primary} name="images" /> <FormImagePicker backgroundColor={colors.primary} name="images" />
<SubmitButton title="Enviar" backgroundColor={colors.primary} /> <SubmitButton title="Enviar" backgroundColor={colors.primary} />
@ -176,6 +188,10 @@ const styles = StyleSheet.create({
textAlign: "center", textAlign: "center",
marginTop: 10, marginTop: 10,
}, },
error_txt: {
fontSize: 18,
color: colors.danger,
},
}); });
export default RainSharingDataScreen; export default RainSharingDataScreen;

17
src/app/screens/RiverFloodSharingDataScreen.js

@ -15,14 +15,15 @@ import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view
import assets from "../config/assets"; import assets from "../config/assets";
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
images: Yup.array().min(1, "Por favor, selecione ao menos uma imagem"),
images: Yup.array(),
}); });
const borderWidth = 4; const borderWidth = 4;
function RiverFloodSharingDataScreen(props) { function RiverFloodSharingDataScreen(props) {
const [riverScale, setRiverScale] = useState(0);
const [riverScale, setRiverScale] = useState(-1);
const location = useLocation(); const location = useLocation();
const [error, setError] = useState(false);
return ( return (
<Screen style={styles.container}> <Screen style={styles.container}>
@ -47,6 +48,10 @@ function RiverFloodSharingDataScreen(props) {
images: [], images: [],
}} }}
onSubmit={(values) => { onSubmit={(values) => {
if (riverScale == -1) {
setError(true);
return;
}
insertRiverData({ ...values, riverScale, location }); insertRiverData({ ...values, riverScale, location });
showMessage({ showMessage({
message: "Informação enviada!", message: "Informação enviada!",
@ -124,6 +129,10 @@ function RiverFloodSharingDataScreen(props) {
</View> </View>
</View> </View>
{error && riverScale == -1 && (
<Text style={styles.error_txt}>Selecione ao menos uma opção</Text>
)}
<FormImagePicker backgroundColor={colors.primary} name="images" /> <FormImagePicker backgroundColor={colors.primary} name="images" />
<SubmitButton title="Enviar" backgroundColor={colors.primary} /> <SubmitButton title="Enviar" backgroundColor={colors.primary} />
@ -156,6 +165,10 @@ const styles = StyleSheet.create({
textAlign: "center", textAlign: "center",
marginTop: 10, marginTop: 10,
}, },
error_txt: {
fontSize: 18,
color: colors.danger,
},
}); });
export default RiverFloodSharingDataScreen; export default RiverFloodSharingDataScreen;

24
src/app/screens/SharingFloodZonesScreen.js

@ -15,18 +15,18 @@ import Screen from "../components/Screen";
import assets from "../config/assets"; import assets from "../config/assets";
function submitForm(props) { function submitForm(props) {
console.log(props);
insertFloodZone(props); insertFloodZone(props);
} }
const validationSchema = Yup.object().shape({ const validationSchema = Yup.object().shape({
images: Yup.array().min(1, "Por favor, selecione ao menos uma imagem"),
description: Yup.string()
.label("Description")
.required("Por favor, forneça uma descrição"),
images: Yup.array(),
description: Yup.string().label("Description"),
}); });
function SharingFloodZonesScreen(props) { function SharingFloodZonesScreen(props) {
const [passable, setPassable] = useState(0);
const [passable, setPassable] = useState(-1);
const [error, setError] = useState(false);
const location = useLocation(); const location = useLocation();
return ( return (
@ -53,6 +53,10 @@ function SharingFloodZonesScreen(props) {
description: "", description: "",
}} }}
onSubmit={(values) => { onSubmit={(values) => {
if (passable == -1) {
setError(true);
return;
}
submitForm({ ...values, passable, location }); submitForm({ ...values, passable, location });
showMessage({ showMessage({
message: "Informação enviada!", message: "Informação enviada!",
@ -92,6 +96,10 @@ function SharingFloodZonesScreen(props) {
</TouchableNativeFeedback> </TouchableNativeFeedback>
</View> </View>
{error && passable == -1 && (
<Text style={styles.error_txt}>Selecione ao menos uma opção</Text>
)}
<FormImagePicker name="images" height={10} /> <FormImagePicker name="images" height={10} />
<FormField <FormField
maxLength={255} maxLength={255}
@ -106,7 +114,7 @@ function SharingFloodZonesScreen(props) {
</Screen> </Screen>
); );
} }
const borderWidth = 3;
const borderWidth = 4;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
@ -142,6 +150,10 @@ const styles = StyleSheet.create({
text: { text: {
fontSize: 14, fontSize: 14,
}, },
error_txt: {
fontSize: 18,
color: colors.danger,
},
}); });
export default SharingFloodZonesScreen; export default SharingFloodZonesScreen;
Loading…
Cancel
Save