diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java index 798d9b1d0..8b50f65b9 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/utils/FormUtils.java @@ -292,9 +292,6 @@ public static Map createRadioButtonAndCheckBoxLabel(String stepNam labelText.setTag(R.id.original_text, Html.fromHtml(combinedLabelText)); labelText.setTextSize(labelTextSize); canvasIds.put(labelConstraintLayout.getId()); - if (readOnly) { - editButton.setVisibility(View.VISIBLE); - } labelConstraintLayout.setEnabled(!readOnly); linearLayout.addView(labelConstraintLayout); createdViewsMap.put(JsonFormConstants.EDIT_BUTTON, editButton); @@ -363,8 +360,8 @@ public static void showInfoIcon(String stepName, JSONObject jsonObject, CommonLi } } - public static void showEditButton(JSONObject jsonObject, View editableView, ImageView editButton, - CommonListener listener) throws JSONException { + public static void setEditButtonAttributes(JSONObject jsonObject, View editableView, ImageView editButton, + CommonListener listener) throws JSONException { editButton.setTag(R.id.editable_view, editableView); editButton.setTag(R.id.key, jsonObject.getString(JsonFormConstants.KEY)); editButton.setTag(R.id.type, jsonObject.getString("type")); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/CheckBoxFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/CheckBoxFactory.java index 6dedf81bc..539d1cc97 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/CheckBoxFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/CheckBoxFactory.java @@ -61,9 +61,14 @@ private List attachJson(String stepName, Context context, JSONObject jsonO String openMrsEntityId = jsonObject.getString(JsonFormConstants.OPENMRS_ENTITY_ID); boolean readOnly = false; + boolean editable = false; + if (jsonObject.has(JsonFormConstants.READ_ONLY)) { readOnly = jsonObject.getBoolean(JsonFormConstants.READ_ONLY); } + if (jsonObject.has(JsonFormConstants.EDITABLE)) { + editable = jsonObject.getBoolean(JsonFormConstants.EDITABLE); + } List views = new ArrayList<>(1); JSONArray canvasIds = new JSONArray(); @@ -90,6 +95,9 @@ private List attachJson(String stepName, Context context, JSONObject jsonO editButton = (ImageView) labelViews.get(JsonFormConstants.EDIT_BUTTON); if (editButton != null) { showEditButton(jsonObject, editableCheckBoxes, editButton, listener); + if(editable){ + editButton.setVisibility(View.VISIBLE); + } } } diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java index 8e8e6bdc5..6fa2cba11 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/EditTextFactory.java @@ -81,7 +81,7 @@ private List attachJson(String stepName, Context context, JsonFormFragment MaterialEditText editText = editTextLayout.findViewById(R.id.edit_text); ImageView editButton = editTextLayout.findViewById(R.id.material_edit_text_edit_button); - FormUtils.showEditButton(jsonObject, editText, editButton, listener); + FormUtils.setEditButtonAttributes(jsonObject, editText, editButton, listener); attachLayout(stepName, context, formFragment, jsonObject, editText, editButton); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java index 878474c7b..c66bfaa09 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeEditTextFactory.java @@ -68,7 +68,7 @@ private List attachJson(String stepName, Context context, JsonFormFragment getLayout(), null); NativeEditText editText = rootLayout.findViewById(R.id.normal_edit_text); ImageView editButton = rootLayout.findViewById(R.id.normal_edit_text_edit_button); - FormUtils.showEditButton(jsonObject, editText, editButton, listener); + FormUtils.setEditButtonAttributes(jsonObject, editText, editButton, listener); makeFromJson(stepName, context, formFragment, jsonObject, editText, editButton); addRequiredValidator(jsonObject, editText); diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java index 932210833..a503da804 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/NativeRadioButtonFactory.java @@ -40,7 +40,6 @@ import java.util.List; import java.util.Map; -import static com.vijay.jsonwizard.utils.FormUtils.showEditButton; import static com.vijay.jsonwizard.widgets.DatePickerFactory.DATE_FORMAT; @@ -264,9 +263,13 @@ protected List attachJson(String stepName, Context context, JsonFormFragme this.canvasIds = canvasIds; boolean readOnly = false; + boolean editable = false; if (jsonObject.has(JsonFormConstants.READ_ONLY)) { readOnly = jsonObject.getBoolean(JsonFormConstants.READ_ONLY); } + if (jsonObject.has(JsonFormConstants.EDITABLE)) { + editable = jsonObject.getBoolean(JsonFormConstants.EDITABLE); + } List views = new ArrayList<>(1); ImageView editButton; @@ -282,9 +285,11 @@ protected List attachJson(String stepName, Context context, JsonFormFragme if (labelViews != null && labelViews.size() > 0) { editButton = (ImageView) labelViews.get(JsonFormConstants.EDIT_BUTTON); if (editButton != null) { - showEditButton(jsonObject, radioGroup, editButton, listener); + FormUtils.setEditButtonAttributes(jsonObject, radioGroup, editButton, listener); + if(editable){ + editButton.setVisibility(View.VISIBLE); + } } - } rootLayout.setTag(R.id.extraPopup, popup); views.add(rootLayout); 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 ce6e317b4..1fbd6939f 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 @@ -97,7 +97,7 @@ private void addSpinner(JSONObject jsonObject, RelativeLayout spinnerRelativeLay MaterialSpinner spinner = spinnerRelativeLayout.findViewById(R.id.material_spinner); ImageView spinnerInfoIconImageView = spinnerRelativeLayout.findViewById(R.id.spinner_info_icon); ImageView editButton = spinnerRelativeLayout.findViewById(R.id.spinner_edit_button); - FormUtils.showEditButton(jsonObject, spinner, editButton, listener); + FormUtils.setEditButtonAttributes(jsonObject, spinner, editButton, listener); String hint = jsonObject.optString(JsonFormConstants.HINT); if (!TextUtils.isEmpty(hint)) { spinner.setHint(jsonObject.getString(JsonFormConstants.HINT)); diff --git a/sample/src/main/assets/json.form/single_form.json b/sample/src/main/assets/json.form/single_form.json index 2d8882cdf..08be83622 100644 --- a/sample/src/main/assets/json.form/single_form.json +++ b/sample/src/main/assets/json.form/single_form.json @@ -157,8 +157,7 @@ "openmrs_entity_parent": "", "openmrs_entity": "person_attribute", "openmrs_entity_id": "Child_Register_Card_Number", - "editable": true, - "read_only": false, + "read_only": true, "value": "1891389133", "type": "edit_text", "hint": "Child's register card number" @@ -635,6 +634,7 @@ "label_text_color": "#FF9800", "hint": "Any delivery complications?", "read_only": true, + "editable": true, "exclusive": [ "none" ], @@ -744,7 +744,7 @@ "label": "Any symptoms of severe pre-eclampsia?", "label_text_style": "bold", "text_color": "#000000", - "read_only": true, + "editable": true, "exclusive": [ "none" ], @@ -971,7 +971,8 @@ "value": true, "err": "Please select where stock was issued" } - },{ + }, + { "key": "site_ipv_assess", "openmrs_entity_parent": "", "openmrs_entity": "", @@ -1319,12 +1320,13 @@ "edit_type": "name", "edit_text_style": "bordered", "value": "1909319333", + "editable": true, "v_required": { "value": "true", "err": "Please enter the last name" }, "v_regex": { - "value": "[A-Za-z\\s\.\-]*", + "value": "[0-9]*", "err": "Please enter a valid name" } }, @@ -1337,13 +1339,14 @@ "hint": "Guardians name *", "edit_type": "name", "read_only": true, + "editable": true, "edit_text_style": "bordered", "v_required": { "value": "true", "err": "Please enter the guardians name" }, "v_regex": { - "value": "[A-Za-z\\s\.\-]*", + "value": "[A-Za-z\\s\\.\\-]*", "err": "Please enter a valid name" } },