https://github.com/ibrahimsn98/Freya
A lightweight, simplified form validation library for Android
https://github.com/ibrahimsn98/Freya
Last synced: 22 days ago
JSON representation
A lightweight, simplified form validation library for Android
- Host: GitHub
- URL: https://github.com/ibrahimsn98/Freya
- Owner: ibrahimsn98
- License: mit
- Created: 2021-03-15T15:54:12.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-03-15T18:23:11.000Z (about 4 years ago)
- Last Synced: 2025-04-11T20:43:53.920Z (23 days ago)
- Language: Kotlin
- Size: 2.99 MB
- Stars: 89
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - ibrahimsn98/Freya - A lightweight, simplified form validation library for Android (Kotlin)
README
A lightweight, simplified form validation library for Android
[](https://jitpack.io/#ibrahimsn98/freya)
[](https://opensource.org/licenses/MIT)## Screenshots
## Validation Rules Setup
```xml
```
## Form Layout Setup
```xml
```
## Validation on Form Submit
```kotlin
val freya = findViewById(R.id.freya)
val submitButton = findViewById(R.id.submit)/*
* Listens if the whole form is valid
*/
freya.onValidationChangeListener = {
Log.d(TAG, "Is form valid: $it")
}/*
* Listens for form validation errors after validate()
*/
freya.onErrorListener = {
Log.d(TAG, "Validation errors: $it")
}submitButton.setOnClickListener {
Log.d(TAG, "Is form valid: ${freya.validate()} values: ${freya.values}")
}
```## Realtime Field Validation
```kotlin
/*
* Listens for validation changes of any form field
*/
freya.onFieldValidationChangeListener = {
when (it.error) {
is Ruler.Required -> {
it.setError("This field is required.")
}
is Ruler.Email -> {
it.setError("Please enter a valid email address.")
}
is Ruler.PhoneNumber -> {
it.setError("Please enter a valid phone number.")
}
is Ruler.MinSize -> {
it.setError("This field must contain at least ${it.error?.param} characters.")
}
is Ruler.MaxSize -> {
it.setError("This field must contain at most ${it.error?.param} characters.")
}
is Ruler.Regex -> {
it.setError("Please provide a valid data.")
}
}
}
```## Get Values & Prefill Form
```kotlin
val values: Map = freya.valuesfreya.setup(
mapOf(
R.id.inputUsername to "Thomas"
)
)```
## Note
Currently supported field view types are `TextInputLayout`, `TextInputEditText`, `EditText`.
Support for more view types and new validation rules will be added in the future.[Download Demo APK](https://github.com/ibrahimsn98/freya/blob/master/app/demo.apk)
## Setup
> Follow me on Twitter [@ibrahimsn98](https://twitter.com/ibrahimsn98)
Step 1. Add the JitPack repository to your build file
```groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```groovy
dependencies {
implementation 'com.github.ibrahimsn98:freya:1.0.0'
}
```## License
```
MIT LicenseCopyright (c) 2020 İbrahim Süren
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```