A lightweight, simplified form validation library for Android

Related tags

Utility Freya
Overview

A lightweight, simplified form validation library for Android

License: MIT

Screenshots

Validation Rules Setup

">
xml version="1.0" encoding="utf-8" ?>
<resources xmlns:app="http://schemas.android.com/apk/res-auto">

    <formField
        app:id="@id/inputUsername"
        app:required="true"
        app:minSize="3"
        app:maxSize="25" />

    <formField
        app:id="@id/inputEmail"
        app:email="true" />

    <formField
        app:id="@id/inputPhone"
        app:required="true"
        app:phoneNumber="true" />

    <formField
        app:id="@id/inputPassword"
        app:required="true"
        app:minSize="3"
        app:maxSize="25" />

resources>

Form Layout Setup

">
<me.ibrahimsn.lib.FreyaForm
    android:id="@+id/freya"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:config="@xml/form_app">

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/inputEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="12dp">

        <com.google.android.material.textfield.TextInputEditText
            android:inputType="textEmailAddress"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Email Address"/>

    com.google.android.material.textfield.TextInputLayout>

    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/inputPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:passwordToggleEnabled="true"
        android:layout_marginBottom="16dp">

        <com.google.android.material.textfield.TextInputEditText
            android:inputType="textPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"/>

    com.google.android.material.textfield.TextInputLayout>

me.ibrahimsn.lib.FreyaForm>

Validation on Form Submit

val freya = findViewById<FreyaForm>(R.id.freya)
val submitButton = findViewById<Button>(R.id.submit)

/*
 * Listens if the whole form is valid
 */
freya.onValidationChangeListener = {
    Log.d(TAG, "Is form valid: $it")
}

/*
 * Listens for form validation errors after validate()
 */
freya.onErrorListener = {
    Log.d(TAG, "Validation errors: $it")
}

submitButton.setOnClickListener {
    Log.d(TAG, "Is form valid: ${freya.validate()} values: ${freya.values}")
}

Realtime Field Validation

{ it.setError("Please enter a valid email address.") } is Ruler.PhoneNumber -> { it.setError("Please enter a valid phone number.") } is Ruler.MinSize -> { it.setError("This field must contain at least ${it.error?.param} characters.") } is Ruler.MaxSize -> { it.setError("This field must contain at most ${it.error?.param} characters.") } is Ruler.Regex -> { it.setError("Please provide a valid data.") } } } ">
/*
 * Listens for validation changes of any form field
 */
freya.onFieldValidationChangeListener = {
    when (it.error) {
        is Ruler.Required -> {
            it.setError("This field is required.")
        }
        is Ruler.Email -> {
            it.setError("Please enter a valid email address.")
        }
        is Ruler.PhoneNumber -> {
            it.setError("Please enter a valid phone number.")
        }
        is Ruler.MinSize -> {
            it.setError("This field must contain at least ${it.error?.param} characters.")
        }
        is Ruler.MaxSize -> {
            it.setError("This field must contain at most ${it.error?.param} characters.")
        }
        is Ruler.Regex -> {
            it.setError("Please provide a valid data.")
        }
    }
}

Get Values & Prefill Form

val values: Map<Int, Any?> = freya.values

freya.setup(
    mapOf(
        R.id.inputUsername to "Thomas"
    )
)

Note

Currently supported field view types are TextInputLayout, TextInputEditText, EditText. Support for more view types and new validation rules will be added in the future.

Download Demo APK

Setup

Follow me on Twitter @ibrahimsn98

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.ibrahimsn98:freya:1.0.0'
}

License

MIT License

Copyright (c) 2020 İbrahim Süren

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
Simple-Keyboard - A quick lightweight keyboard app that helps chatting with your friends, or inserting any other texts, numbers or symbols Android library which makes it  easy to handle the different obstacles while calling an API (Web Service) in Android App.
Android library which makes it easy to handle the different obstacles while calling an API (Web Service) in Android App.

API Calling Flow API Calling Flow is a Android library which can help you to simplify handling different conditions while calling an API (Web Service)

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

Android Utilities Library build in kotlin Provide user 100 of pre defined method to create advanced native android app.

A robust native library loader for Android.
A robust native library loader for Android.

ReLinker A robust native library loader for Android. More information can be found in our blog post Min SDK: 9 JavaDoc Overview The Android PackageMan

Joda-Time library with Android specialization

joda-time-android This library is a version of Joda-Time built with Android in mind. Why Joda-Time? Android has built-in date and time handling - why

UPnP/DLNA library for Java and Android

Cling EOL: This project is no longer actively maintained, code may be outdated. If you are interested in maintaining and developing this project, comm

:iphone: [Android Library] Get device information in a super easy way.
:iphone: [Android Library] Get device information in a super easy way.

EasyDeviceInfo Android library to get device information in a super easy way. The library is built for simplicity and approachability. It not only eli

Android library for viewing, editing and sharing in app databases.
Android library for viewing, editing and sharing in app databases.

DbInspector DbInspector provides a simple way to view the contents of the in-app database for debugging purposes. There is no need to pull the databas

Android Market In-app Billing Library

Update In-app Billing v2 API is deprecated and will be shut down in January 2015. This library was developed for v2 a long time ago. If your app is st

Releases(1.0.0)
Owner
İbrahim Süren
${user.bio}
İbrahim Süren
Simple-Claim-Form - Android App for creating a simple dynamic form with MVVM architecture

Simple-Claim-Form Android App for creating a simple dynamic form with MVVM archi

Shubham Gangpuri 1 Aug 14, 2022
Android gallery & photo/video functionality simplified with RxJava2

RxGallery Android gallery & photo/video functionality simplified with RxJava2 Setup To use this library your minSdkVersion must be >= 9. Add it in you

Brian Rojas 38 Oct 11, 2022
Compose easy forms validation library

Compose EasyForms Focus on building your form UI while the library do the heavy work for you. Features Built in support for most of the Form widgets i

Kosh Sergani 24 Jul 18, 2022
Kotlin validation with a focus on readability

kommodus Kotlin validation with a focus on readability import com.github.kommodus.constraints.* import com.github.kommodus.Validation data class Test

Serhii Shobotov 0 Dec 12, 2021
Validator - Notify type based validation for input fields.

Validator - Notify type based validation for input fields.

Mustafa Yiğit 57 Dec 8, 2022
Sample project displaying process of OTP validation using firebase

OTP-Validation-using-firebase Sample project displaying process of OTP validation using firebase Screenshots Concepts used Integrated Firebase sdk for

Ankita Gaba 2 Jun 18, 2022
Form Validator Library for Android

Android-Validator Form Validator Library for Android [](https://flattr.com/submit/auto?user_id=throrin19&url=https://github.com/throrin19/Android-Vali

Benjamin Besse 449 Dec 17, 2022
App to simulate making lemonada juice in form of attractive application

Project: Lemonade App - Starter Code Starter code for the first independent project for Android Basics in Kotlin Introduction This is the starter code

null 0 Oct 28, 2021
Mi-FreeForm - An APP that is activated through Shizuku/Sui and can display most apps in the form of freeform

Mi-FreeForm 简体中文 Mi-FreeForm is an APP that is activated through Shizuku/Sui and

KindBrive 181 Dec 31, 2022
A lightweight library for config and using SharedPreferences

preferences-helper SharePreferences is very popular with any project and all most all project has SharePreferences for saving data. This library will

Khang Tran 23 May 8, 2021