Skip to content

Commit

Permalink
Merge pull request #183 from OpenSRP/feature/spinner_keys
Browse files Browse the repository at this point in the history
Added alias support for Spinners
  • Loading branch information
rkodev authored May 6, 2019
2 parents 2ea21a6 + 04d37d5 commit bd1c5d3
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class JsonFormConstants {
public static final String BEHAVIOUR = "behaviour";
public static final String RESULT = "result";
public static final String VALUE = "value";
public static final String KEYS = "keys";
public static final String SECOND_VALUE = "second_value";
public static final String OPENMRS_ENTITY_PARENT = "openmrs_entity_parent";
public static final String OPENMRS_ENTITY = "openmrs_entity";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,21 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
String openMrsEntityParent = (String) parent.getTag(R.id.openmrs_entity_parent);
String openMrsEntity = (String) parent.getTag(R.id.openmrs_entity);
String openMrsEntityId = (String) parent.getTag(R.id.openmrs_entity_id);
JSONArray jsonArray = (JSONArray) parent.getTag(R.id.keys);
CustomTextView customTextView = (CustomTextView) parent.getTag(R.id.number_selector_textview);
Boolean popup = (Boolean) parent.getTag(R.id.extraPopup);
if (popup == null) {
popup = false;
}

String value = parent.getItemAtPosition(position).toString();
if (jsonArray != null && position > -1 && jsonArray.length() > 0) {
try {
value = jsonArray.getString(position);
} catch (JSONException e) {
e.printStackTrace();
}
}
getView().writeValue(mStepName, parentKey, value, openMrsEntityParent, openMrsEntity, openMrsEntityId, popup);

if (JsonFormConstants.NUMBER_SELECTOR.equals(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay
spinner.setFloatingLabelText(jsonObject.getString(JsonFormConstants.HINT));
}

JSONArray keysJson = null;
if (jsonObject.has(JsonFormConstants.KEYS)) {
keysJson = jsonObject.getJSONArray(JsonFormConstants.KEYS);
spinner.setTag(R.id.keys, keysJson);
}

setViewTags(jsonObject, canvasIds, stepName, popup, openMrsEntityParent, openMrsEntity, openMrsEntityId, spinner);

addSkipLogicTags(context, relevance, constraints, calculations, spinner);
Expand Down Expand Up @@ -131,7 +137,9 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay
values = new String[valuesJson.length()];
for (int i = 0; i < valuesJson.length(); i++) {
values[i] = valuesJson.optString(i);
if (valueToSelect.equals(values[i])) {
if (keysJson == null && valueToSelect.equals(values[i])) {
indexToSelect = i;
} else if (keysJson != null && valueToSelect.equals(keysJson.optString(i))) {
indexToSelect = i;
}
}
Expand Down
1 change: 1 addition & 0 deletions android-json-form-wizard/src/main/res/values/ids.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<item name="openmrs_entity_parent" type='id' />
<item name="openmrs_entity" type='id' />
<item name="openmrs_entity_id" type='id' />
<item name="keys" type='id' />
<item name="relevance" type="id" />
<item name="calculation" type="id" />
<item name="constraints" type="id" />
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.6.2-SNAPSHOT
VERSION_NAME=1.6.3-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Native Form Json Wizard
Expand Down
24 changes: 24 additions & 0 deletions sample/src/main/assets/json.form/single_form.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,30 @@
"err": "Please enter the sex"
}
},
{
"key": "marital",
"openmrs_entity_parent": "",
"openmrs_entity": "person",
"openmrs_entity_id": "person_attribute",
"type": "spinner",
"hint": "Marital Status",
"values": [
"Ame OA",
"Haja OA"
],
"keys": [
"Married",
"Single"
],
"v_required": {
"value": "true",
"err": "Please enter the sex"
},
"openmrs_choice_ids": {
"Married": "1107AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"Single": "1713AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
}
},
{
"key": "Date_Birth",
"openmrs_entity_parent": "",
Expand Down

0 comments on commit bd1c5d3

Please sign in to comment.