English | 中文
ViForm
ViForm is a Kotlin library for form validation, mainly aimed at Compose Multiplatform projects. It has the following features:
- Supports Kotlin Multiplatform(android, jvm, js/wasmjs, ios)
- Type-safe validation rules, supporting both DSL style and chained style validation declaration
- Form state management
- Integrated support for Compose Multiplatform(android, desktop, wasmjs, ios)
Prerequisites
- Kotlin Coroutine
- KopyBuilder
- Compose Multiplatform (optional)
Installation
Apply the KopyBuilder Gradle plugin
plugins {
id("io.github.windedge.kopybuilder") version "0.2.4"
}
Add dependency to Multiplatform project
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("io.github.windedge.viform:viform-core:0.2.2")
implementation("io.github.windedge.viform:viform-compose:0.2.2")
}
}
}
}
Add dependency to JVM project
dependencies {
implementation("io.github.windedge.viform:viform-core:0.2.2")
implementation("io.github.windedge.viform:viform-compose:0.2.2")
}
Quick Start
Define validation rules:
io.github.windedge.copybuilder.KopyBuilder
io.github.windedge.viform.core.*
(
name: String = ,
email: String? = ,
password: String = ,
confirmPassword: String = ,
)
schema = FormSchema.create<Signup> {
field(Signup::name) {
required()
isAlphaNumeric()
}
field(Signup::email).optional {
isEmail()
}
field(Signup::password).required().lengthBetween(, )
field(Signup::confirmPassword).required().lengthBetween(, )
.custom() {
it == field(Signup::password).currentValue
}
}
Use in Jetpack Compose project:
Known Issues
When compiling the WebAssembly (WASM) target, you may encounter the error Can't link symbol kotlin.internal.ir/ANDAND.
License
MIT License
Author
Ken Xu