Skip to content

Commit

Permalink
Merge pull request #466 from OpenSRP/issue1733-radio-button-check
Browse files Browse the repository at this point in the history
Added ability to set the radio button as checked on re-opening the form
  • Loading branch information
qaziabubakar-vd authored Mar 30, 2021
2 parents b339216 + febccc0 commit 63c3999
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion opensrp-chw-anc/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
POM_SETTING_NAME=OpenSRP Client Chw Anc
POM_SETTING_ARTIFACT_ID=opensrp-client-chw-anc
POM_SETTING_PACKAGING=aar
VERSION_NAME=2.0.3-SNAPSHOT
VERSION_NAME=2.0.4-SNAPSHOT
VERSION_CODE=1
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class BaseAncHomeVisitFragment extends BaseHomeVisitFragment implements V
private SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
private List<JSONObject> optionList = new ArrayList<>();
private Map<String, String> dateConstraints = new HashMap<>();
private String value;
private RadioButton radioButtonChecked;

public static BaseAncHomeVisitFragment getInstance(final BaseAncHomeVisitContract.VisitView view, String form_name, JSONObject json, Map<String, List<VisitDetail>> details, String count) {
JSONObject jsonObject = json;
Expand Down Expand Up @@ -228,12 +230,19 @@ private void prepareRadioView() {

try {
rb.setText(object.getString(JsonFormConstants.TEXT));

String key = object.getString(JsonFormConstants.KEY);
if (key.equalsIgnoreCase(value)) {
rb.setChecked(true);
radioButtonChecked = rb;
}
rb.setTag(R.id.home_visit_radio_key, key);
rb.setOnClickListener(v -> {
if (rb.isChecked())
if (rb.isChecked() && !radioButtonChecked.equals(rb)) {
radioButtonChecked.setChecked(false);
rb.setChecked(true);
onSelectOption(key);
radioButtonChecked = rb;
}
});
} catch (JSONException e) {
Timber.e(e);
Expand Down Expand Up @@ -370,6 +379,7 @@ public void setCount(String count) {

@Override
public void setValue(String value) {
this.value = value;
if (getQuestionType() == QuestionType.BOOLEAN) {
if (radioButtonNo != null && radioButtonYes != null) {
setYesNoListenersActive(false);
Expand Down

0 comments on commit 63c3999

Please sign in to comment.