valifi
valifi copied to clipboard
Android library for validation forms and inputs based on data binding
ValiFi
- ValiFi is android library for validating fields or whole forms.
- It's working with data binding and validations are visible immediately when user adds input.
- It's highly customizable and simple for use.
- works with kotlin
Features
- predefined fields (password, email, username, ..)
- forms for lots of fields
- custom and asynchronous validations
- option for own fields
How to use
Initialize the library
1. Add gradle dependency
implementation 'com.mlykotom:valifi:1.5.0'
2. Setup project with data binding
android{
...
dataBinding.enabled = true
...
}
3. Install the library in application class
public class MyApplication extends Application {
@Override
public void onCreate() {
ValiFi.install(this);
}
}
Use in your code
1. Create field you want to validate
public final ValiFieldEmail email = new ValiFieldEmail();
2. Use it from layout
Library uses two-way data binding so be careful of adding android:text="@={...}"
<android.support.design.widget.TextInputLayout
...
app:errorEnabled="true"
app:error="@{viewModel.email.error}">
<android.support.design.widget.TextInputEditText
...
android:text="@={viewModel.email.value}"
android:hint="E-mail address" />
</android.support.design.widget.TextInputLayout>
...
<Button
...
android:enabled="@{viewModel.email.valid}"
android:text="Submit" />
3. Destroy the field
In order to prevent leaks, field must be destroyed before destroying the screen!
This is easily done by calling:
@Override
public void onDestroy() {
email.destroy();
super.onDestroy();
}
That's it!
When user types his e-mail, it will automatically validates input and enables/disables submit button.
For customizations information visit Wiki
App Examples
- MVVM approach (preferred) here
- Classic fragment approach here
- [deprecated + removed] MVVM approach here
License
Copyright 2018 Tomas Mlynaric
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.