A form validation library for android jetpack compose

Overview

FormValidator

A form validation library for android jetpack compose

Features

  • Determine Validation Flow. Flow.Dowm|Flow.Up|Flow.Splash
  • Custom Validation
  • Validation Snackbar
  • Validation State Callbacks
  • Library is well documented

Preview

device-2022-01-15-014026.mp4

Example

(null) } var email by remember { mutableStateOf("") } var emailError by remember { mutableStateOf (null) } val nameField = "Name" val emailField = "Email" val validator = FormValidator( fields = listOf( ValidationField( value = name, name = nameField, onError = { nameError = it }), ValidationField( value = email, onError = { emailError = it }, type = FormValidator.Type.Email ) ) ) Form( validator = validator, modifier = Modifier .fillMaxSize() .verticalScroll(state = rememberScrollState()) .padding(16.dp) ) { Spacer(modifier = Modifier.height(30.dp)) AppTextField( label = nameField, value = name, placeholder = "Enter name", onValueChanged = { name = it }, errorMessage = nameError ) Spacer(modifier = Modifier.height(16.dp)) AppTextField( label = emailField, value = email, placeholder = "Enter email", onValueChanged = { email = it }, errorMessage = emailError, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email) ) Spacer(modifier = Modifier.height(40.dp)) AppButton(text = "Submit") { if(validator.validate()) showToast(validator.errorMessage) } } }">
@Composable
    fun ScreenContent() {
        var name by remember { mutableStateOf("") }
        var nameError by remember { mutableStateOf<String?>(null) }
        var email by remember { mutableStateOf("") }
        var emailError by remember { mutableStateOf<String?>(null) }
        val nameField = "Name"
        val emailField = "Email"
        val validator = FormValidator(
            fields = listOf(
                ValidationField(
                    value = name,
                    name = nameField,
                    onError = {
                        nameError = it
                    }),
                ValidationField(
                    value = email,
                    onError = {
                        emailError = it
                    }, type = FormValidator.Type.Email
                )
            )
        )
        Form(
            validator = validator,
            modifier = Modifier
                .fillMaxSize()
                .verticalScroll(state = rememberScrollState())
                .padding(16.dp)
        ) {
            Spacer(modifier = Modifier.height(30.dp))
            AppTextField(
                label = nameField,
                value = name,
                placeholder = "Enter name",
                onValueChanged = { name = it },
                errorMessage = nameError
            )
            Spacer(modifier = Modifier.height(16.dp))
            AppTextField(
                label = emailField,
                value = email,
                placeholder = "Enter email",
                onValueChanged = { email = it },
                errorMessage = emailError,
                keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email)
            )
            Spacer(modifier = Modifier.height(40.dp))
            AppButton(text = "Submit") {
                if(validator.validate())
                    showToast(validator.errorMessage)
            }
        }
    }

Getting started

Step 1. Add the JitPack repository to your build file

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

dependencies {
	        implementation 'com.github.funyin:FormValidator:1.0.0'
	}
You might also like...
Android.compose.squircle - Android LightWeight Squircle Library for JetPack Compose

Android LightWeight Squircle Library for JetPack Compose Usage Based on Compose

A Kotlin library to use Jetpack Compose in Android and iOS. Allow to write UI for both in Kotin. Still experimental as many compose features are not yet available.
A Kotlin library to use Jetpack Compose in Android and iOS. Allow to write UI for both in Kotin. Still experimental as many compose features are not yet available.

Multiplatform Compose A Kotlin library to use Jetpack Compose in Android and iOS. Allow to write UI for both in Kotin. Still experimental as many comp

Compose Curved-Scroll is an Android Jetpack Compose library made with ❤️
Compose Curved-Scroll is an Android Jetpack Compose library made with ❤️

Compose-Curved-Scroll-library Compose Curved-Scroll is an Android Jetpack Compos

Compose-html - An Android library which provides HTML support for Jetpack Compose texts
Compose-html - An Android library which provides HTML support for Jetpack Compose texts

HtmlCompose An Android library which provides HTML support for Jetpack Compose t

Compose-Ratingbar-library - A simple implementation for rating bar in Jetpack Compose

Compose-Ratingbar-library - A simple implementation for rating bar in Jetpack Compose

Lightweight library to tweak the fling behaviour in Android. This library is only compatible with Jetpack-Compose.
Lightweight library to tweak the fling behaviour in Android. This library is only compatible with Jetpack-Compose.

Flinger (Only compatible with compose) What is Flinger? Flinger is a plugin that is made on top of jetpack compose that will help the developer to twe

An application that i developed with a aim of learning Jetpack compose and many other jetpack libraries
An application that i developed with a aim of learning Jetpack compose and many other jetpack libraries

An application that i developed with a aim of learning Jetpack compose and many other jetpack libraries, The application make use of jikan Api which displays a list of animations,there more details and even trailers of the animations.

Compose-Instagram-Profile-UI - Instagram profile screen UI using android jetpack compose
Compose-Instagram-Profile-UI - Instagram profile screen UI using android jetpack compose

Compose-Intsgram-Profile-UI Instagram profile screen UI using android jetpack co

Svg-to-compose-intellij - A simple Android Studio plugin to generate Jetpack Compose ImageVector icons

svg-to-compose-intellij A simple Android Studio plugin to generate Jetpack Compo

Comments
  • Configure Renovate

    Configure Renovate

    Mend Renovate

    Welcome to Renovate! This is an onboarding PR to help you understand and configure settings before regular Pull Requests begin.

    🚦 To activate Renovate, merge this Pull Request. To disable Renovate, simply close this Pull Request unmerged.


    Detected Package Files

    • gradle.properties (gradle)
    • settings.gradle (gradle)
    • build.gradle (gradle)
    • FormValidator/build.gradle (gradle)
    • app/build.gradle (gradle)
    • gradle/wrapper/gradle-wrapper.properties (gradle-wrapper)

    Configuration

    🔡 Renovate has detected a custom config for this PR. Feel free to ask for help if you have any doubts and would like it reviewed.

    Important: Now that this branch is edited, Renovate can't rebase it from the base branch any more. If you make changes to the base branch that could impact this onboarding PR, please merge them manually.

    What to Expect

    With your current configuration, Renovate will create 11 Pull Requests:

    Update dependency androidx.test.ext:junit to v1.1.4
    • Schedule: ["at any time"]
    • Branch name: renovate/androidx.test.ext-junit-1.x
    • Merge into: master
    • Upgrade androidx.test.ext:junit to 1.1.4
    Update compose_version to v1.3.1
    Update dependency androidx.activity:activity-compose to v1.6.1
    Update dependency androidx.appcompat:appcompat to v1.5.1
    • Schedule: ["at any time"]
    • Branch name: renovate/androidx.appcompat-appcompat-1.x
    • Merge into: master
    • Upgrade androidx.appcompat:appcompat to 1.5.1
    Update dependency androidx.core:core-ktx to v1.9.0
    • Schedule: ["at any time"]
    • Branch name: renovate/androidx.core-core-ktx-1.x
    • Merge into: master
    • Upgrade androidx.core:core-ktx to 1.9.0
    Update dependency androidx.lifecycle:lifecycle-runtime-ktx to v2.5.1
    Update dependency androidx.test.espresso:espresso-core to v3.5.0
    • Schedule: ["at any time"]
    • Branch name: renovate/androidx.test.espresso-espresso-core-3.x
    • Merge into: master
    • Upgrade androidx.test.espresso:espresso-core to 3.5.0
    Update dependency com.android.tools.build:gradle to v7.3.1
    • Schedule: ["at any time"]
    • Branch name: renovate/com.android.tools.build-gradle-7.x
    • Merge into: master
    • Upgrade com.android.tools.build:gradle to 7.3.1
    Update dependency com.google.android.material:material to v1.7.0
    Update dependency gradle to v7.5.1
    • Schedule: ["at any time"]
    • Branch name: renovate/gradle-7.x
    • Merge into: master
    • Upgrade gradle to 7.5.1
    Update dependency org.jetbrains.kotlin:kotlin-gradle-plugin to v1.7.21

    🚸 Branch creation will be limited to maximum 2 per hour, so it doesn't swamp any CI resources or spam the project. See docs for prhourlylimit for details.


    ❓ Got questions? Check out Renovate's Docs, particularly the Getting Started section. If you need any further assistance then you can also request help here.


    This PR has been generated by Mend Renovate. View repository job log here.

    opened by renovate[bot] 0
Releases(1.0.0)
Owner
Funyinoluwa Kashimawo
Mobile developer (Kotlin/Dart )
Funyinoluwa Kashimawo
Field state manager and basic set of validation, fields

Compose Forms Field state manager and basic set of validation, fields

Vitaliy Zarubin 9 Jan 4, 2022
Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

Learn Jetpack Compose for Android by Examples. Learn how to use Jetpack Compose for Android App Development. Android’s modern toolkit for building native UI.

MindOrks 382 Jan 5, 2023
Jetpack Compose Boids | Flocking Insect 🐜. bird or Fish simulation using Jetpack Compose Desktop 🚀, using Canvas API 🎨

?? ?? ?? Compose flocking Ants(boids) ?? ?? ?? Jetpack compose Boids | Flocking Insect. bird or Fish simulation using Jetpack Compose Desktop ?? , usi

Chetan Gupta 38 Sep 25, 2022
A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Why Not Compose! A collection of animations, compositions, UIs using Jetpack Compose. You can say Jetpack Compose cookbook or play-ground if you want!

Md. Mahmudul Hasan Shohag 186 Jan 1, 2023
This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Compose.

JetBMICalculator This is a sample app(For beginners - App #2) built using Jetpack Compose. It demonstrates the concept of State Hoisting in Jetpack Co

BHAVNA THACKER 3 Dec 31, 2022
Jetpack-Compose-Demo - Instagram Profile UI using Jetpack Compose

Jetpack-Compose-Demo Instagram Profile UI using Jetpack Compose

omar 1 Aug 11, 2022
Jetpack-compose-animations-examples - Cool animations implemented with Jetpack compose

Jetpack-compose-animations-examples This repository consists of 4 animations: St

Canopas Software 180 Jan 2, 2023
Compose-navigation - Set of utils to help with integrating Jetpack Compose and Jetpack's Navigation

Jetpack Compose Navigation Set of utils to help with integrating Jetpack Compose

Adam Kobus 5 Apr 5, 2022
Jetpack-compose-uis - A collection of some UIs using Jetpack Compose. built using Katalog

Jetpack Compose UIs This is a collection of some UIs using Jetpack Compose. It i

Mori Atsushi 3 Dec 15, 2022
A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose

Authentication A simple authentication application using Jetpack compose to illustrate signin and sign up using Mvvm, Kotlin and jetpack compose Scree

Felix Kariuki 5 Dec 29, 2022