5 Star 3 Fork 0

HarmonyOS-TPC / ohos-validation-komensky

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
README.md 4.45 KB
一键复制 编辑 原始数据 按行查看 历史
Satish 提交于 2021-04-21 23:25 . update README.md.

ohos-validation-komensky

ohos-validation-komensky : A simple library for validating user input in forms using annotations.

ohos-validation-komensky includes :

  • Validate all views at once and show feedback to user. With one line of code.
  • Live validation - check user input as he moves between views with immediate feedback.
  • Extensible library - you can add your own validations or adapters for custom views.

Usage Instructions

A sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the sample/ folder.

How to validate

First, annotate your views like this:

@NotEmpty(messageId = R.string.validation_name)
@MinLength(value = 3, messageId = R.string.validation_name_length, order = 2)
private EditText mNameEditText;

Now you are ready to:

FormValidator.validate(this, new SimpleErrorPopupCallback(this, true, element));

You will receive collection of all failed validations in a callback and you can present them to the user as you want. Or simply use prepared callbacks (like SimpleErrorPopupCallback).

Live validation

To start and stop live validation, simply call:

FormValidator.startLiveValidation(this, formContainer, new SimpleErrorPopupCallback(this, false, element));
FormValidator.stopLiveValidation(this);

List of all supported validation annotations

Validations supported out of the box:

@NotEmpty(messageId = R.string.validation_name, order = 1)
private EditText mNameEditText;
@MinLength(value = 1, messageId = R.string.validation_participants, order = 2)
private EditText mNameEditText;
@MinValue(value = 2L, messageId = R.string.validation_name_length)
private EditText mEditNumberOfParticipants;
@MinNumberValue(value = "5.5", messageId = R.string.validation_name_length)
private EditText mEditPotentialOfHydrogen;
@RegExp(value = EMAIL, messageId = R.string.validation_valid_email)
private EditText mEditEmail;
@RegExp(value = "^[0-9]+$", messageId = R.string.validation_valid_count)
private EditText mEditCount;
@DateInFuture(messageId = R.string.validation_date)
private TextView mTxtDate;
@DateNoWeekend(messageId = R.string.validation_date_weekend)
private TextView mTxtDate;
@Custom(value = MyVeryOwnValidator.class, messageId = R.string.validation_custom)
private EditText mNameEditText;

Installation instructions

  1. For using ohos-validation-komensky module in your sample application, add below dependencies:

    dependencies {
    	implementation project(':library')
    	testImplementation 'junit:junit:4.13'
    	ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100'
    }
  2. For using ohos-validation-komensky in separate application, add the below dependencies and include "library.har" in libs folder of "entry" module :

    dependencies {
    	implementation files('libs/library.har')
    }
  3. For using ohos-validation-komensky from a remote repository in separate application, add the below dependencies in build.gradle of "entry" module :

    dependencies {
    	  implementation 'io.openharmony.tpc.thirdlib:ohos-validation-komensky:1.0.1'
    }
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/HarmonyOS-tpc/ohos-validation-komensky.git
git@gitee.com:HarmonyOS-tpc/ohos-validation-komensky.git
HarmonyOS-tpc
ohos-validation-komensky
ohos-validation-komensky
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891