Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix show errors of all invalid fields from all steps for multi-step form on save. #658

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager;
Expand All @@ -22,6 +23,7 @@
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
Expand Down Expand Up @@ -385,7 +387,7 @@ public boolean areFormViewsFilled() {

} else if (childView instanceof MaterialEditText) {
MaterialEditText editView = (MaterialEditText) childView;
boolean noValidation = (!childView.isEnabled() || !editView.hasValidators());
boolean noValidation = (!childView.isEnabled() || !editView.hasValidators());
boolean valid = true;
if (!noValidation && editView.getValidators() != null) {
for (METValidator validator : editView.getValidators()) {
Expand Down Expand Up @@ -520,7 +522,9 @@ public void validateAndWriteValues() {
}

//remove invalid fields not belonging to current step since formdata view are cleared when view is created
if (invalidFields != null && !invalidFields.isEmpty()) {
final String nextStep = getFormFragment().getJsonApi().nextStep();
// Check if this is the last step, then skip removing invalid fields from other steps, so that the final step has all invalid fields
if (StringUtils.isNotBlank(nextStep) && invalidFields != null && !invalidFields.isEmpty()) {
for (Map.Entry<String, ValidationStatus> entry : invalidFields.entrySet()) {
String key = entry.getKey();
if (StringUtils.isNotBlank(key) && !key.startsWith(mStepName)) {
Expand All @@ -535,7 +539,7 @@ public void validateAndWriteValues() {
* Check if alarm is ringing and stop it if so
*/
public void checkAndStopCountdownAlarm() {
formFragment.getJsonApi().getAppExecutors().diskIO().execute(()->{
formFragment.getJsonApi().getAppExecutors().diskIO().execute(() -> {
try {
JSONObject formJSONObject = new JSONObject(formFragment.getCurrentJsonState());
JSONArray fields = FormUtils.fields(formJSONObject, mStepName);
Expand Down Expand Up @@ -1083,7 +1087,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
String.valueOf(compoundButton.isChecked()), openMrsEntityParent, openMrsEntity,
openMrsEntityId, popup);
} else if ((compoundButton instanceof AppCompatRadioButton || compoundButton instanceof RadioButton)
&& isChecked) {
&& isChecked) {
String parentKey = (String) compoundButton.getTag(R.id.key);
String openMrsEntityParent = (String) compoundButton.getTag(R.id.openmrs_entity_parent);
String openMrsEntity = (String) compoundButton.getTag(R.id.openmrs_entity);
Expand Down Expand Up @@ -1269,6 +1273,7 @@ private void addRules(JSONObject jsonObject, Set<String> ruleFiles) {
}

}

public void cleanUp() {
cleanupAndExit = true;
mJsonFormInteractor.cleanUp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ public void testSetTextColor() {
customTextView.setTextColor(expectedTextColor);
Assert.assertEquals(expectedTextColor, customTextView.getTextColors().getDefaultColor());
}

@Test
public void testIsHintOnText() {
boolean isHintOnText = customTextView.isHintOnText();
Assert.assertTrue(isHintOnText);
}
}