-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added the masked character support and Referenced field #663
Open
junaidwarsivd
wants to merge
3
commits into
master
Choose a base branch
from
character_masking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...izard/src/main/java/com/vijay/jsonwizard/validators/edittext/ReferenceFieldValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.vijay.jsonwizard.validators.edittext; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.rengwuxian.materialedittext.MaterialEditText; | ||
import com.rengwuxian.materialedittext.validation.METValidator; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ReferenceFieldValidator extends METValidator { | ||
MaterialEditText referenceField; | ||
public ReferenceFieldValidator(@NonNull @NotNull String errorMessage,MaterialEditText referenceField) { | ||
super(errorMessage); | ||
this.referenceField = referenceField; | ||
} | ||
|
||
@Override | ||
public boolean isValid(@NonNull @NotNull CharSequence charSequence, boolean isEmpty) { | ||
if(!isEmpty) { | ||
String referenceText = referenceField.getText().toString(); | ||
return referenceText.equals(charSequence.toString()); | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
package com.vijay.jsonwizard.widgets; | ||
|
||
import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_CUMULATIVE_VALIDATION_ERR; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MAX_VALIDATION_ERR; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MIN_VALIDATION_ERR; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.KEY; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATED_FIELDS; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATIVE_VALIDATION_EXCEPTION; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP1; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.V_CUMULATIVE_TOTAL; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MAX; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MIN; | ||
import static com.vijay.jsonwizard.utils.FormUtils.fields; | ||
import static com.vijay.jsonwizard.utils.FormUtils.getFieldJSONObject; | ||
|
||
import android.content.Context; | ||
import android.text.Editable; | ||
import android.text.InputFilter; | ||
import android.text.InputType; | ||
import android.text.TextUtils; | ||
import android.text.TextWatcher; | ||
import android.text.method.PasswordTransformationMethod; | ||
import android.util.Patterns; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
|
@@ -43,6 +31,7 @@ | |
import com.vijay.jsonwizard.validators.edittext.MaxNumericValidator; | ||
import com.vijay.jsonwizard.validators.edittext.MinLengthValidator; | ||
import com.vijay.jsonwizard.validators.edittext.MinNumericValidator; | ||
import com.vijay.jsonwizard.validators.edittext.ReferenceFieldValidator; | ||
import com.vijay.jsonwizard.validators.edittext.ReferenceValidator; | ||
import com.vijay.jsonwizard.validators.edittext.RelativeNumericValidator; | ||
import com.vijay.jsonwizard.validators.edittext.RequiredValidator; | ||
|
@@ -60,6 +49,19 @@ | |
|
||
import timber.log.Timber; | ||
|
||
import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_CUMULATIVE_VALIDATION_ERR; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MAX_VALIDATION_ERR; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.DEFAULT_RELATIVE_MIN_VALIDATION_ERR; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.KEY; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATED_FIELDS; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.RELATIVE_VALIDATION_EXCEPTION; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.STEP1; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.V_CUMULATIVE_TOTAL; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MAX; | ||
import static com.vijay.jsonwizard.constants.JsonFormConstants.V_RELATIVE_MIN; | ||
import static com.vijay.jsonwizard.utils.FormUtils.fields; | ||
import static com.vijay.jsonwizard.utils.FormUtils.getFieldJSONObject; | ||
|
||
public class EditTextFactory implements FormWidgetFactory { | ||
|
||
public static final int MIN_LENGTH = 0; | ||
|
@@ -117,7 +119,6 @@ protected List<View> attachJson(String stepName, Context context, JsonFormFragme | |
RelativeLayout editTextLayout = rootLayout.findViewById(R.id.edit_text_layout); | ||
MaterialEditText editText = editTextLayout.findViewById(R.id.edit_text); | ||
ImageView editButton = editTextLayout.findViewById(R.id.material_edit_text_edit_button); | ||
|
||
FormUtils.setEditButtonAttributes(jsonObject, editText, editButton, listener); | ||
attachLayout(stepName, context, formFragment, jsonObject, editText, editButton); | ||
|
||
|
@@ -179,6 +180,7 @@ public void run() { | |
FormUtils.toggleEditTextVisibility(jsonObject, editText); | ||
|
||
addRequiredValidator(jsonObject, editText); | ||
addEqualsValidator(formFragment,jsonObject,editText); | ||
addLengthValidator(jsonObject, editText); | ||
addRegexValidator(jsonObject, editText); | ||
addEmailValidator(jsonObject, editText); | ||
|
@@ -190,15 +192,19 @@ public void run() { | |
addCumulativeTotalValidator(jsonObject, formFragment, editText, stepName, (JsonApi) context); | ||
// edit type check | ||
String editType = jsonObject.optString(JsonFormConstants.EDIT_TYPE); | ||
editText.setSingleLine(false); | ||
if (!TextUtils.isEmpty(editType)) { | ||
if (JsonFormConstants.NUMBER.equals(editType)) { | ||
editText.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); | ||
} else if (JsonFormConstants.NAME.equals(editType)) { | ||
editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS); | ||
} | ||
} | ||
else if (JsonFormConstants.PASSWORD.equals(editType)) | ||
{ | ||
editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); | ||
} | ||
|
||
editText.setSingleLine(false); | ||
} | ||
editText.addTextChangedListener(new GenericTextWatcher(stepName, formFragment, editText)); | ||
attachRefreshLogic(context, jsonObject, editText); | ||
} | ||
|
@@ -212,6 +218,15 @@ private void attachInfoIcon(String stepName, JSONObject jsonObject, RelativeLayo | |
|
||
} | ||
|
||
private void addEqualsValidator(JsonFormFragment formFragment,JSONObject jsonObject, MaterialEditText editText) throws JSONException { | ||
JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_EQUALS); | ||
if (requiredObject != null) { | ||
String referencedValue = requiredObject.optString(JsonFormConstants.VALUE,""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
MaterialEditText referencedEditText = (MaterialEditText) formFragment.getJsonApi().getFormDataView(referencedValue); | ||
editText.addValidator(new ReferenceFieldValidator(requiredObject.getString(JsonFormConstants.ERR),referencedEditText)); | ||
FormUtils.setRequiredOnHint(editText); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that this is not a required field configuration, is |
||
} | ||
} | ||
private void addRequiredValidator(JSONObject jsonObject, MaterialEditText editText) throws JSONException { | ||
JSONObject requiredObject = jsonObject.optJSONObject(JsonFormConstants.V_REQUIRED); | ||
if (requiredObject != null) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this return true?? What is the reference field has a some text and it not empty itself?