From 5b343d4d0edd9d2417026b33792cbf5693d04020 Mon Sep 17 00:00:00 2001 From: ShivamPokhriyal Date: Thu, 19 Mar 2020 15:11:56 +0530 Subject: [PATCH 1/2] Fix for navigation of saved form In case of validation condition on a non-required question, navigation of submitted form gives constraint violation error for validation error --- .../org/commcare/activities/FormEntryActivityUIController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/org/commcare/activities/FormEntryActivityUIController.java b/app/src/org/commcare/activities/FormEntryActivityUIController.java index 9ec3433ec3..217dcae94b 100644 --- a/app/src/org/commcare/activities/FormEntryActivityUIController.java +++ b/app/src/org/commcare/activities/FormEntryActivityUIController.java @@ -392,7 +392,7 @@ private void showNextView(boolean resuming) { } if (activity.currentPromptIsQuestion()) { - if (!activity.saveAnswersForCurrentScreen(FormEntryConstants.EVALUATE_CONSTRAINTS)) { + if (!activity.saveAnswersForCurrentScreen(!activity.mFormController.isFormReadOnly())) { // A constraint was violated so a dialog should be showing. return; } From 252cca18b5177cc0314d20fd93c0b74ef0649077 Mon Sep 17 00:00:00 2001 From: ShivamPokhriyal Date: Tue, 24 Mar 2020 11:13:42 +0530 Subject: [PATCH 2/2] Remove FormEntryConstants for evaluating constraints --- .../commcare/activities/FormEntryActivity.java | 18 +++++++++--------- .../FormEntryActivityUIController.java | 4 ++-- .../components/FormEntryConstants.java | 2 -- .../components/FormEntryDialogs.java | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/src/org/commcare/activities/FormEntryActivity.java b/app/src/org/commcare/activities/FormEntryActivity.java index 497c713a85..81e213ced8 100644 --- a/app/src/org/commcare/activities/FormEntryActivity.java +++ b/app/src/org/commcare/activities/FormEntryActivity.java @@ -327,7 +327,7 @@ public void onActivityResultSessionSafe(int requestCode, int resultCode, Intent case FormEntryConstants.LOCATION_CAPTURE: String sl = intent.getStringExtra(FormEntryConstants.LOCATION_RESULT); uiController.questionsView.setBinaryData(sl, mFormController); - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); break; case FormEntryConstants.HIERARCHY_ACTIVITY: case FormEntryConstants.HIERARCHY_ACTIVITY_FIRST_START: @@ -351,7 +351,7 @@ private void resetPendingCalloutIndex() { public void saveImageWidgetAnswer(String imagePath) { uiController.questionsView.setBinaryData(imagePath, mFormController); - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); onExternalAttachmentUpdated(); uiController.refreshView(); } @@ -370,7 +370,7 @@ private void processChooserResponse(Intent intent) { } else { uiController.questionsView.setBinaryData(media, mFormController); } - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); onExternalAttachmentUpdated(); uiController.refreshView(); } @@ -500,7 +500,7 @@ public boolean onOptionsItemSelected(MenuItem item) { return true; case FormEntryConstants.MENU_HIERARCHY_VIEW: if (currentPromptIsQuestion()) { - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); } Intent i = new Intent(this, FormHierarchyActivity.class); startActivityForResult(i, FormEntryConstants.HIERARCHY_ACTIVITY); @@ -648,7 +648,7 @@ public Object onRetainCustomNonConfigurationInstance() { // mFormEntryController is static so we don't need to pass it. if (mFormController != null && currentPromptIsQuestion() && uiController.questionsView != null) { - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); } return null; } @@ -746,7 +746,7 @@ private void saveDataToDisk(boolean exit, boolean complete, String updatedSaveNa // save current answer; if headless, don't evaluate the constraints // before doing so. boolean wasScreenSaved = - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS, complete, headless); + saveAnswersForCurrentScreen(false, complete, headless); if (!wasScreenSaved) { return; } @@ -782,7 +782,7 @@ public void setFormLanguage(String[] languages, int index) { mFormController.setLanguage(languages[index]); dismissAlertDialog(); if (currentPromptIsQuestion()) { - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); } uiController.refreshView(); invalidateOptionsMenu(); @@ -819,7 +819,7 @@ protected void onPause() { super.onPause(); if (!isFinishing() && uiController.questionsView != null && currentPromptIsQuestion()) { - saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(false); } if (mLocationServiceIssueReceiver != null) { @@ -1151,7 +1151,7 @@ public void savingComplete(SaveToDiskTask.SaveStatus saveStatus, String errorMes // an answer constraint was violated, so try to save the // current question to trigger the constraint violation message uiController.refreshView(); - saveAnswersForCurrentScreen(FormEntryConstants.EVALUATE_CONSTRAINTS); + saveAnswersForCurrentScreen(true); return; case SAVE_ERROR: if (!CommCareApplication.instance().isConsumerApp()) { diff --git a/app/src/org/commcare/activities/FormEntryActivityUIController.java b/app/src/org/commcare/activities/FormEntryActivityUIController.java index 217dcae94b..6d582a2171 100644 --- a/app/src/org/commcare/activities/FormEntryActivityUIController.java +++ b/app/src/org/commcare/activities/FormEntryActivityUIController.java @@ -285,7 +285,7 @@ protected void showPreviousView(boolean showSwipeAnimation) { // The answer is saved on a back swipe, but question constraints are ignored. if (activity.currentPromptIsQuestion()) { - activity.saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + activity.saveAnswersForCurrentScreen(false); } // Any info stored about the last changed widget is useless when we move to a new view @@ -717,7 +717,7 @@ protected void updateFormRelevancies() { ArrayList oldQuestionTexts = FormRelevancyUpdating.getOldQuestionTextsForEachWidget(oldWidgets); - activity.saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + activity.saveAnswersForCurrentScreen(false); FormEntryPrompt[] newValidPrompts; try { diff --git a/app/src/org/commcare/activities/components/FormEntryConstants.java b/app/src/org/commcare/activities/components/FormEntryConstants.java index 6d299601c1..0641fc965c 100644 --- a/app/src/org/commcare/activities/components/FormEntryConstants.java +++ b/app/src/org/commcare/activities/components/FormEntryConstants.java @@ -6,8 +6,6 @@ public class FormEntryConstants { // Defines for FormEntryActivity public static final boolean EXIT = true; public static final boolean DO_NOT_EXIT = false; - public static final boolean EVALUATE_CONSTRAINTS = true; - public static final boolean DO_NOT_EVALUATE_CONSTRAINTS = false; // Request codes for returning data from specified intent. public static final int IMAGE_CAPTURE = 1; diff --git a/app/src/org/commcare/activities/components/FormEntryDialogs.java b/app/src/org/commcare/activities/components/FormEntryDialogs.java index 2c515e8551..22d1843cca 100644 --- a/app/src/org/commcare/activities/components/FormEntryDialogs.java +++ b/app/src/org/commcare/activities/components/FormEntryDialogs.java @@ -103,7 +103,7 @@ public static void createClearDialog(final FormEntryActivity activity, switch (i) { case DialogInterface.BUTTON_POSITIVE: activity.clearAnswer(qw); - activity.saveAnswersForCurrentScreen(FormEntryConstants.DO_NOT_EVALUATE_CONSTRAINTS); + activity.saveAnswersForCurrentScreen(false); break; case DialogInterface.BUTTON_NEGATIVE: break;