Skip to content

chrisjenx/yakcov

Folders and files

NameName
Last commit message
Last commit date

Latest commit

7d4ddf7 · Oct 2, 2024

History

55 Commits
Jul 25, 2024
Oct 2, 2024
Jul 19, 2024
Oct 2, 2024
Aug 23, 2024
Jul 19, 2024
Oct 2, 2024
Jul 23, 2024
Jul 24, 2024
Aug 19, 2024
Aug 19, 2024
Jul 19, 2024

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:allTests