Skip to content

Commit

Permalink
make a dialog not dismissable if form errors available for improved ux
Browse files Browse the repository at this point in the history
  • Loading branch information
maulidkategile committed Oct 19, 2023
1 parent 2970604 commit e152b50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,7 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
selected_group_lv_adapter.setSelectedPosition(position);
});

builder.setPositiveButton(R.string.ok, (dialog, which) -> {
if (selectedPosition1 == -1) {
Toast.makeText(requireContext(), "Caregiver information missing", Toast.LENGTH_SHORT).show();
dialogDismissListener.onFailure();
dialog.dismiss();
}else if (selectedPosition2 == -1 && childrenDividedIntoGroups) {
Toast.makeText(requireContext(), "Child missing the group", Toast.LENGTH_SHORT).show();
dialogDismissListener.onFailure();
dialog.dismiss();
}else {
handleSuccess(dialog);
}
});
builder.setPositiveButton(R.string.ok, null);

builder.setNegativeButton(R.string.cancel, (dialog, which) -> {
dialogDismissListener.onFailure();
Expand All @@ -170,6 +158,27 @@ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
return builder.create();
}

@Override
public void onResume() {
AlertDialog dialog = (AlertDialog) getDialog();
assert dialog != null;
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (selectedPosition1 == -1) {
dialogValidationFail(dialog, getString(R.string.came_with_pc_lv));
}else if (selectedPosition2 == -1 && childrenDividedIntoGroups) {
dialogValidationFail(dialog, getString(R.string.selected_group_lv));
}else {
handleSuccess(dialog);
}
}
});
super.onResume();
}

void handleSuccess(DialogInterface dialogInterface){
String otherCompanion = who_came_with_the_child_lv_other.getText().toString();
if(selectedPosition1 == 0){
Expand Down Expand Up @@ -212,7 +221,6 @@ void handleSuccess(DialogInterface dialogInterface){
void dialogValidationFail(DialogInterface dialogInterface,String message){
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show();
dialogDismissListener.onFailure();
dialogInterface.dismiss();
}

void dialogValidationSuccess(DialogInterface dialogInterface){
Expand Down
2 changes: 2 additions & 0 deletions opensrp-chw/src/kk/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,6 @@
<string name="cg_rep_lv_other_error">Tafadhari jaza mtu mwingine ambae alikuja kwa niaba ya mlezi wa mtoto</string>
<string name="who_came_with_the_child_lv_error">Tafadhari chagua walezi/watu wengine waliohudhuria</string>
<string name="who_came_with_the_child_lv_other_error">Tafadhari jaza mlezi/mtu mwingine aliyehudhuria</string>
<string name="came_with_pc_lv">Tafadhari bainisha kama mtoto amekuja na mlezi wake</string>
<string name="selected_group_lv">Tafadhari chagua kundi la mototo</string>
</resources>
2 changes: 2 additions & 0 deletions opensrp-chw/src/kk/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,6 @@
<string name="cg_rep_lv_other_error">Other caregiver representative missing</string>
<string name="who_came_with_the_child_lv_error">The companions of caregiver missing</string>
<string name="who_came_with_the_child_lv_other_error">Other companion of caregiver missing</string>
<string name="came_with_pc_lv">Caregiver information missing</string>
<string name="selected_group_lv">Child missing the group</string>
</resources>

0 comments on commit e152b50

Please sign in to comment.