EasyForm


Source link: https://github.com/emmasuzuki/EasyForm

EasyForm

Inspired by AngularJS's ng-pattern, required etc., EasyForm makes field validation with just an xml and easy. You set error properties and message in xml and EasyForm will show error message when it is needed. Optinally, a button can be disabled when there is an error and enabled when all fields have valid inputs.

Disclaimer

This project is still with minimal features. I am very happy to accept any feature requests, bug reports. Please feel free to open Issues and I will try my best to prioritize it. I really like to ask for any additional feature ideas since a form varies for different product domains and I am bad at see all aspects of those use cases.

Installation

Install via gradle.

compile 'com.emmasuzuki:easyform:1.2.0' 

Example

<?xml version="1.0" encoding="utf-8"?> <com.emmasuzuki.easyform.EasyForm xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  app:submitButton="@+id/submit_button"
  app:showErrorOn="unfocus">

<com.emmasuzuki.easyform.EasyTextInputLayout

android:id="@+id/empty_check_input"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:errorMessage="@string/error_message_empty"

app:errorType="empty" />

<com.emmasuzuki.easyform.EasyTextInputLayout

android:id="@+id/digit_check_input"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/empty_check_input"

android:layout_marginTop="4dp"

app:errorMessage="@string/error_message_digit"

app:regexPattern="[0-9]+" />

<Button

android:id="@id/submit_button"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_below="@id/digit_check_input"

android:background="@color/colorAccent"

android:text="@string/submit"

android:textColor="@android:color/white" />  </com.emmasuzuki.easyform.EasyForm>

Custom Views

EasyForm

EasyFrom is a ViewGroup which you wrap all form components inside. EasyForm is extending RelativeLayout, so you align any child views with just like you do for RelativeLayout.

Properties

Attributes Type Description
submitButton reference A submit button can be disable/enable based on field condition by setting view ID to submitButton property.
showErrorOn enum (unfocus/change) A field is validated and error will be displayed on unfocus of the field or on every keystroke. default: change

NOTE: If showErrorOn is set to "unfocus", submitButton will be enabled when user correctly filled all fields except the last one, so make sure to call easyForm.validate(); on submitButton click in your application. Check out LongFormFragment for the usage.

APIs

Function Description
void validate() Validate all fields if the fields meet a criteria or not.
boolean isValid() Return true if all fields have valid values.

EasyFormEditText

EasyFormEditText extends EditText that will apply an error message by built-in setError() based on input and validation criteria.

EasyTextInputLayout

EasyTextInputLayout extends TextInputLayout. Similar to EasyFormEditText, this applies an error message by built-in setError(). EasyTextInputLayout adds EditText automatically, so unlike you do with TextInputLayout, you do not have to add EditText as a child.

EasyAutoCompleteTextView

EasyAutoCompleteTextView extends AutoCompleteTextView. By passing items, auto complete values will be displayed using default simple drop down view. Similar to EasyFormEditText, this also has the form validation feature and as EasyFormEditText, it applies an error message by built-in setError().

Properties

Attributes Type Description EasyForm
EditText
EasyText
InputLayout
EasyAuto
Complete
TextView
errorMessage string,
referene
Set an error message to show when a validation criteria does not match. ? ? ?
errorType enum (empty, pattern,
value, chars).
Set errorType. ? ? ? (Only empty, pattern, chars)
regexPattern string,
reference
Set a regex to match against an input. If an input does not match with the regex, an error message will be displayed. Setting this automatically set errorType to pattern. ? ? ?
minValue float Set a minimum value (inclusive). Setting this automatically set errorType to value. ? ?
maxValue float Set a maximum value (inclusive). You can conbine with minValue. Setting this automatically set errorType to value. ? ?
minChars integer Set a minimum char length (inclusive). Setting this automatically set errorType to chars. ? ? ?
maxChars integer Set a maximum char length (inclusive). You can conbine with minChars. Setting this automatically set errorType to chars. ? ? ?
items reference Set list of suggestions for auto complete. ?
textSize dimension Set a textSize for an internal EditText. ?
textColor color,
reference
Set a textColor for an internal EditText. ?
android:
inputType
Bypass android's inputType to internal EditText. ?

API

Function Description EasyForm
EditText
EasyText
InputLayout
EasyAuto
Complete
TextView
void setErrorMessage(String) Set an error message to show when a validation criteria does not match. ? ? ?
void setErrorType(ErrorType) Set errorType (EMPTY, PATTERN, VALUE, CHARS). ? ? ?
void setRegexPattern(String) Set a regex to match against an input. If an input does not match with the regex, an error message will be displayed. Setting this automatically set errorType to pattern. ? ? ?
void setMinValue(int) Set a minimum value (inclusive). Setting this automatically set errorType to value. ? ?
void setMaxValue(int) Set a maximum value (inclusive). You can conbine with minValue. Setting this automatically set errorType to value. ? ?
void setMinChars(int) Set a minimum char length (inclusive). Setting this automatically set errorType to chars. ? ? ?
void setMaxChars(int) Set a maximum char length (inclusive). You can conbine with minChars. Setting this automatically set errorType to chars. ? ? ?
void setItems(String [])
void setItems(List<String>)
Set list of suggestions for auto complete. ?

More Examples

Check out Sample folder.

Feature Request, Bug Report

I am very happy to hear all of these. To keep this project going, please file an issue for any requests. File Issue

License

Copyright 2016 Emma Suzuki [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

Qiscus SDK is a lightweight and powerful android chat library. Qiscus SDK will allow you to easily integrating Qiscus engine with your apps to make cool chatting application.

UniversalPreferences is simple Android library that allows you to use Shared Preferences in an easy way.

ShortRoid Library makes it easier to use different functionalities of android. Main objective is to simplify android code and make the development process faster. ShortRoid being open source encourages contributers to contribute and make it more fun for the developers to develop android apps using ShortRoid.

Present your progress bars in arc mode with information and total control.

A RecyclerView component.

This is a Tinder like android stretch top ScrollView / pull to zoom custom View.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes