|
| 1 | +# ValidatableTextInputLayout |
| 2 | + |
| 3 | +[](https://circleci.com/gh/Kyash/validatable-textinput-layout/tree/master) |
| 4 | +[](https://jitpack.io/#Kyash/validatable-textinput-layout) |
| 5 | + |
| 6 | +ValidatableTextInputLayout is the view which extended TextInputLayout to validate the input text easily for . |
| 7 | + |
| 8 | +## Download |
| 9 | + |
| 10 | +Project build.gradle |
| 11 | + |
| 12 | +```groovy |
| 13 | +allprojects { |
| 14 | + repositories { |
| 15 | + ... |
| 16 | + maven { url "https://jitpack.io" } |
| 17 | + } |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +App build.gradle |
| 22 | + |
| 23 | +```groovy |
| 24 | +dependencies { |
| 25 | + ... |
| 26 | + compile 'com.kyash.vtl:validatable-textinput-layout:LATEST_VERSION' |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +`LATEST_VERSION` is [](https://jitpack.io/#Kyash/validatable-textinput-layout) |
| 31 | + |
| 32 | +## Basic usage |
| 33 | +You can use as same as `TextInputLayout` in layout xml. |
| 34 | + |
| 35 | +### Layout |
| 36 | +`trigger` attribute defines the timing of the text field validation. |
| 37 | + |
| 38 | +```xml |
| 39 | +<co.kyash.vtl.ValidatableTextInputLayout |
| 40 | + id="@id/first_name" |
| 41 | + android:layout_width="match_parent" |
| 42 | + android:layout_height="wrap_content" |
| 43 | + app:trigger="text_changed"> |
| 44 | + |
| 45 | + <EditText |
| 46 | + android:layout_width="match_parent" |
| 47 | + android:layout_height="wrap_content" |
| 48 | + android:hint="@string/first_name" |
| 49 | + android:inputType="textPersonName" /> |
| 50 | + |
| 51 | +</co.kyash.vtl.ValidatableTextInputLayout> |
| 52 | +``` |
| 53 | + |
| 54 | +### Kotlin |
| 55 | +Register Validator class to `ValidatableTextInputLayout` |
| 56 | +For example, `RequiredValidator` shows error when the field is empty. |
| 57 | + |
| 58 | +```kotlin |
| 59 | +private fun initValidator() { |
| 60 | + binding.firstName.register(RequiredValidator(getString(R.string.validation_error_required))) |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +That's it. It works as below. |
| 65 | + |
| 66 | +<img src="art/required_validator.gif" width="300"> |
| 67 | + |
| 68 | +## Triggers |
| 69 | +There are 2 types of the validation trigger attributes. |
| 70 | + |
| 71 | +Attribute | Description |
| 72 | +:--: | :-- |
| 73 | +text_changed | Validate immediately when the text is changed. |
| 74 | +focus_changed | Validate when the focus is changed |
| 75 | + |
| 76 | +## Validators |
| 77 | +This library provides some common validators |
| 78 | + |
| 79 | +Validator | Description |
| 80 | +:--: | :-- |
| 81 | +RequiredValidator | Required validation |
| 82 | +EmailValidator | General Email address validation |
| 83 | +NumberOnlyValidator | Only numbers are permitted |
| 84 | +AsciiOnlyValidator | Only Ascii characters are permitted |
| 85 | +HiraganaOnlyValidator | Only Japanese Hiragana characters are permitted |
| 86 | +KatakanaOnlyValidator | Only Japanese Katakana characters are permitted |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +## Custom validator |
| 91 | +You can create the custom validator by using `VtlValidator`. |
| 92 | +Since `VtlValidator` uses RxJava2, it can handle async logic like API as well! |
| 93 | + |
| 94 | +``` |
| 95 | +
|
| 96 | +``` |
| 97 | + |
| 98 | +## Contributing |
| 99 | +We are always welcome your contribution! |
| 100 | +If you find a bug or want to add new feature, please raise issue. |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +``` |
| 105 | +Copyright 2018 Kyash |
| 106 | +
|
| 107 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 108 | +you may not use this file except in compliance with the License. |
| 109 | +You may obtain a copy of the License at |
| 110 | +
|
| 111 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 112 | +
|
| 113 | +Unless required by applicable law or agreed to in writing, software |
| 114 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 115 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 116 | +See the License for the specific language governing permissions and |
| 117 | +limitations under the License. |
| 118 | +``` |
0 commit comments