diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java
index bce9bc1ee..7a5e7910c 100644
--- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java
+++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/constants/JsonFormConstants.java
@@ -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";
diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java
index b3e48e6fc..126f8adca 100644
--- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java
+++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/presenters/JsonFormFragmentPresenter.java
@@ -685,6 +685,7 @@ 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) {
@@ -692,6 +693,13 @@ public void onItemSelected(AdapterView> parent, View view, int position, long
}
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)) {
diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java
index 010c24952..c4eeb7808 100644
--- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java
+++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/SpinnerFactory.java
@@ -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);
@@ -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;
}
}
diff --git a/android-json-form-wizard/src/main/res/values/ids.xml b/android-json-form-wizard/src/main/res/values/ids.xml
index 6cd0fa8e9..543b9a113 100644
--- a/android-json-form-wizard/src/main/res/values/ids.xml
+++ b/android-json-form-wizard/src/main/res/values/ids.xml
@@ -19,6 +19,7 @@
+
diff --git a/gradle.properties b/gradle.properties
index 3d9442019..58bd09e0d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -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
diff --git a/sample/src/main/assets/json.form/single_form.json b/sample/src/main/assets/json.form/single_form.json
index 72b4d1e24..f0097d60d 100644
--- a/sample/src/main/assets/json.form/single_form.json
+++ b/sample/src/main/assets/json.form/single_form.json
@@ -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": "",