Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/malekkamel/formvalidator
A declarative Form Validation for Android, simple, clean, and customizable.
https://github.com/malekkamel/formvalidator
android android-library android-sdk edittext rxandroid rxandroid2 rxjava validation
Last synced: 1 day ago
JSON representation
A declarative Form Validation for Android, simple, clean, and customizable.
- Host: GitHub
- URL: https://github.com/malekkamel/formvalidator
- Owner: MalekKamel
- Created: 2017-11-11T05:10:20.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T23:57:19.000Z (6 months ago)
- Last Synced: 2025-01-23T18:07:02.322Z (8 days ago)
- Topics: android, android-library, android-sdk, edittext, rxandroid, rxandroid2, rxjava, validation
- Language: Kotlin
- Homepage:
- Size: 73.1 MB
- Stars: 88
- Watchers: 1
- Forks: 12
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
FormValidator
The easiest, most clean Android form validation.
A declarative Form Validation for Android, simple, clean, and customizable.
Every time you create a form, you need to declare fields and write code for for validating each field in the form, and this results in many ```if else``` and a lot of boilerplate. For these reasons **FormValidator** is here, just declare your fields in XML and its validation and all things will be done for you!
# Table of contents
- [Usage](#usage)
- [Installation](#installation)
- [Widgets](#widgets)
- [TextView Widgets](#textview-widgets)
- [Other Widgets](#other-widgets)
- [Validatable interface](#validatable-interface)
- [Form Layout](#form-layout)
- [TextView Validation](#textview-validation)
- [Credit](#credit)
- [License](#-license)# Usage
```xml
```
To trigger validation:
```kotlin
val isFormValid = findViewById(R.id.form).validate()
```In case you don't need `Form`, you can use `FormEditText` just like any regular field and you can trigger validation using:
```kotlin
val isValid = emailFormEditText.validate()
```#### Note
You can nest the fields inside `Form` layout layout in any levels you need:```xml
```
## Installation
#### Gradle:
```groovy
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}dependencies {
// Core
implementation 'com.github.ShabanKamell.FormValidator:core:x.y.z'
// RxJava
implementation 'com.github.ShabanKamell:FormValidator:x.y.z'
}
```(Please replace x, y and z with the latest version numbers: [![](https://jitpack.io/v/ShabanKamell/FormValidator.svg)](https://jitpack.io/#ShabanKamell/FormValidator))
## Widgets
FormValidator has a collection of different widgets that implement `Validatable`. There're `TextView` widgets and other widgets.### TextView Widgets
| **Widget** | **Required attributes** | **Default** |
| -------------------------- | -------------------------------------------------- | --------------------- |
| **FormEditText** | see [TextView Validation](#textview-validation) | - |
| **FormAutoCompleteTextView** | see [TextView Validation](#textview-validation) | - |### Other Widgets
| **Widget** | **Required attributes** | **Default** |
| -------------------------- | -------------------------------------------------- | --------------------- |
| **FormCheckBox** | checkBoxValidation | checked |
| **FormRatingBar** | ratingBarValidation | required |
| **FormSeekBar** | seekBarValidation | required |
| **FormSwitch** | switchValidation | on |
| **FormToggleButton** | toggleButtonValidation | on |## Validatable interface
```Validatable``` is a fubctional interface implemented by widgets to support validation.``` kotlin
interface Validatable {
// return true if valid, false otherwise.
fun validate(): Boolean
}
```
## Form Layout
`Form` is a LinearLayout that warps all widgets and provides APIs for triggering validation with options.Declare `Form` in XML
``` kotlin
```
Set options programmatically``` kotlin
form.options = FormOptions.create {
validationInterceptor = { .. }
ignoreFieldsIds = listOf(R.id.etIgnoredId)
ignoreHiddenFields = true
shakeOnError = true
}
```Trigger Validation
``` kotlin
val isValid = form.validate()// OR
form.validateOnClick(btnValidateForm) { isValid -> ..}
```## TextView Validation
FormValidator contains rich validators for validating ```TextView```. There're are 2 predefined widgets that inherit from `TextView`: `FormEditText` and `FormAutoCompleteTextView`. see full documentation in 👉 👉 [TextView Validation](https://github.com/ShabanKamell/FormValidator/blob/dev/TEXTVIEW.md)### See 'sample' module for the full code.
### Credit
[Android Form EditText](https://github.com/vekexasia/android-edittext-validator).
### 🛡 License
click to reveal License
```
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```