Skip to content

Yet Another Kotlin COmpose Validation library

Notifications You must be signed in to change notification settings

chrisjenx/yakcov

Repository files navigation

Yet Another Kotlin Compose Validation library

Maven Central Version

TextField validation is a pain, hopefully this is a bit easier

val emailValidator = TextFieldValueValidator(
    rules = listOf(Required, Email)
)
with(emailValiator) {
    OutlinedTextField(
        value = value,
        onValueChange = ::onValueChange,
        modifier = Modifier
            .validationConfig(
                // will start validation on loss of focus
                validateOnFocusLost = true,
                // will shake the field when invalid and validate() is called
                shakeOnInvalid = true,
                // when false will delay [isError] until validate() is called
                showErrorOnInteraction = false,
            )
            .fillMaxWidth(),
        label = { Text("Email*") },
        placeholder = { Text("Email") },
        leadingIcon = { Icon(Icons.Default.Email, contentDescription = "Email") },
        isError = isError(), // will mark the field error when validation has started and is invalid
        supportingText = supportingText(), // will show the validation message, or error message
    )
}

Other Features

  • Multiplatform support! Android, JVM, JS, Wasm, iOS!
  • TextFieldValueValidator - a validator for TextFieldValue that can be used with TextField and OutlinedTextField
  • GenericValueValidator - a generic validator that can be used to validate any type
    • Can use with any Composable, not just TextFields!
  • Build in ValueValidatorRules to make putting forms together easier
  • Outcome - Supports different levels of severity for validation messages, Error, Warning, Info, Success
  • ValidationConfig - Allows you to configure how the validation should behave to user interaction

Dependencies

By default we publish to Maven Central.

We publish all targets (Android, JVM, JS, Wasm, iOS) you can include the common library in your project and it will pull in the correct target for what ever targets you have specified.

commonMain {
    dependencies {
        implementation("com.chrisjenx.yakcov:library:${version}")
    }
}

If you only need a specific target you can include that directly, for example for Android:

dependencies {
    implementation("com.chrisjenx.yakcov:library-android:${version}")
}

Build locally

  • check your system with KDoctor
  • install JDK 17 or higher on your machine

Testing

  • You will need Chrome installed for JS based tests to run
  • run tests with ./gradlew :library:test

About

Yet Another Kotlin COmpose Validation library

Resources

Stars

Watchers

Forks