Git Product home page Git Product logo

rxvalidationtextinputlayout's Introduction

RxValidationTextInputLayout

The easiest way to bring validation to EditText with TextInputLayout.

Getting Started

Add dependency to your project using JitPack

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
dependencies {
		implementation 'com.github.KucherenkoIhor:RxValidationTextInputLayout:0.1'
}

Using in XML:

     <com.kucherenko.RxValidationTextInputLayout
                android:id="@+id/tilFirstName"
                style="@style/TextInputLayout.Counter"
                android:layout_marginTop="@dimen/margin_l"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="parent"
                app:help="at least 3 letters"
                app:error="@string/invalid_first_name"
                app:errorTextAppearance="@style/TextAppearance.AppCompat.Small.Error"
                app:helperTextAppearance="@style/TextAppearance.AppCompat.Small.Helper"
                app:regex="@string/regex_name">
    
                <android.support.design.widget.TextInputEditText
                    android:id="@+id/etFirstName"
                    style="@style/EditText.SingleLine"
                    android:hint="@string/hint_first_name"
                    android:imeOptions="actionNext"
                    android:inputType="textPersonName" />
    
            </com.kucherenko.RxValidationTextInputLayout>

And get simple boolean result using RxJava2 in Java code:

 tilFirstName.onReady = { observable ->  
            disposable = observable.subscribe { isValid ->
                btnSignIn.isEnabled = isValid
            }
        }

Features

  • Reactive approach using RxJava2:
tilFirstName.onReady = { observable ->
            disposable = observable.subscribe { isValid ->
                btnSignIn.isEnabled = isValid
            }
        }
  • Or if you want to observe several fields:
val textInputLayouts = arrayOf(
                tilFirstName,
                tilLastName,
                tilEmail,
                tilPhone,
                tilYear,
                tilDob,
                tilPassword,
                tilConfirmPassword)

        RxValidationTextInputLayout.combineOnReady(*textInputLayouts) { observable ->
            disposable = observable.subscribe { btnSignIn.isEnabled = it }
        }

  • Simple regex support: app:regex="@string/regex_name"
  • You can change configuration as you need:
    • You can allow empty state of input field: app:allowEmpty="true"
    • Or disable error showing when filed is empty app:showErrorIfEmpty="true"
  • Compare input with another one app:equalEditText="@id/etPassword". It's useful for password and confirm password fields:

  • Helper text according to Material Design Guidelines

    app:help="Must be the same with password"

  • Error text appears if input text lose focus: app:error="@string/invalid_password"

  • Custom text styles for help and error states: app:errorTextAppearance="@style/TextAppearance.AppCompat.Small.Error" app:helperTextAppearance="@style/TextAppearance.AppCompat.Small.Helper"

Licenses

MIT

rxvalidationtextinputlayout's People

Contributors

kucherenkoihor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.