Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nwagu/forms
A user input management library
https://github.com/nwagu/forms
android forms kotlin kotlin-multiplatform library user-input validation
Last synced: 2 months ago
JSON representation
A user input management library
- Host: GitHub
- URL: https://github.com/nwagu/forms
- Owner: nwagu
- License: mit
- Created: 2020-05-26T07:11:23.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-08T14:08:51.000Z (8 months ago)
- Last Synced: 2024-10-11T11:06:53.260Z (3 months ago)
- Topics: android, forms, kotlin, kotlin-multiplatform, library, user-input, validation
- Language: Kotlin
- Homepage: https://forms.nwagu.com
- Size: 451 KB
- Stars: 20
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Maven Central](https://img.shields.io/maven-central/v/com.nwagu.forms/forms.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.nwagu.forms%22%20AND%20a:%22forms%22)
## A form management library for Android
This simple library aims to add structure to the creation and management of forms on Android.
From simple login forms to more complex forms that contain varying object types.## Usage
Add the dependency
```groovy
dependencies {
// ...
implementation "com.nwagu.forms:forms:2.0.0-alpha09"
}
```See [sample activity](sampleAndroidApp/src/main/java/com/example/forms/MainActivity.kt) for usage
Create your form fields and add them to an instance of Form.
```kotlin
val form = Form(viewModelScope)val name = FormField(required = true)
.apply {
addValidator { validateNotEmpty() }
addTo(form)
}val gender = FormField()
.apply {
addValidator { validateNonNullObject() }
addTo(form)
}
```Update form
```kotlin
nameEdit.doOnTextChanged { text, start, count, after ->
name.value = text?.toString()
}
```Set error reporting to begin on focus changed
```kotlin
nameEdit.setOnFocusChangeListener { v, hasFocus ->
if (!hasFocus)
name.errorReportingEnabled = true
}
```Form fields expose observable feedback and error fields:
```kotlin
name.observe(
lifecycleScope,
onFeedback = {
// display helpful feedback
},
onError = {
nameEdit.error = it
},
onFocusRequest = {
// bring nameEdit to focus
}
)
```#### Tips
1. You can define your custom validation functions. A few generic validators have been added to [FormFieldValidators](forms/src/commonMain/kotlin/com/nwagu/forms/FormFieldValidators.kt).
2. Observe a form field's `focusRequest` to bring the view to focus when the form field has an error.## Note about multiplatform status
You can use this library now on Android or the JVM. I am currently trying it out on the other target platforms, especially iOS.
That's why it's still in alpha.
If you would like to use the older, stable, LiveData-based version of this library just for Android, please use version: `1.0.3`.