From eb95cc54cee9235bf0e5e927c1865e3854875e60 Mon Sep 17 00:00:00 2001 From: Benjamin Mwalimu Date: Tue, 29 Sep 2020 11:14:38 +0300 Subject: [PATCH] :construction: add the required validator method on the factory --- .../jsonwizard/widgets/MultiSelectListFactory.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/MultiSelectListFactory.java b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/MultiSelectListFactory.java index b0b908ab5..e9d3fe7e1 100644 --- a/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/MultiSelectListFactory.java +++ b/android-json-form-wizard/src/main/java/com/vijay/jsonwizard/widgets/MultiSelectListFactory.java @@ -23,6 +23,7 @@ import com.vijay.jsonwizard.adapter.MultiSelectListAdapter; import com.vijay.jsonwizard.adapter.MultiSelectListSelectedAdapter; import com.vijay.jsonwizard.constants.JsonFormConstants; +import com.vijay.jsonwizard.customviews.NativeEditText; import com.vijay.jsonwizard.domain.MultiSelectItem; import com.vijay.jsonwizard.domain.MultiSelectListAccessory; import com.vijay.jsonwizard.fragments.JsonFormFragment; @@ -31,8 +32,10 @@ import com.vijay.jsonwizard.interfaces.JsonApi; import com.vijay.jsonwizard.interfaces.MultiSelectListRepository; import com.vijay.jsonwizard.task.MultiSelectListLoadTask; +import com.vijay.jsonwizard.utils.FormUtils; import com.vijay.jsonwizard.utils.MultiSelectListUtils; import com.vijay.jsonwizard.utils.Utils; +import com.vijay.jsonwizard.validators.edittext.RequiredValidator; import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; @@ -91,6 +94,17 @@ private List attachJson(@NonNull String stepName, @NonNull Context context return views; } + private static void addRequiredValidator(JSONObject jsonObject, NativeEditText editText) throws JSONException { + JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_REQUIRED); + if (requiredObject != null) { + boolean requiredValue = requiredObject.getBoolean(JsonFormConstants.VALUE); + if (Boolean.TRUE.equals(requiredValue)) { + editText.addValidator(new RequiredValidator(requiredObject.getString(JsonFormConstants.ERR))); + FormUtils.setRequiredOnHint(editText); + } + } + } + private void prepareViewChecks(@NonNull RelativeLayout view, @NonNull Context context) { String relevance = jsonObject.optString(JsonFormConstants.RELEVANCE); String constraints = jsonObject.optString(JsonFormConstants.CONSTRAINTS);