wellingtoncosta / convalida Goto Github PK
View Code? Open in Web Editor NEWA simple, lightweight and powerful field validation library for Android.
Home Page: https://wellingtoncosta.github.io/convalida
License: Apache License 2.0
A simple, lightweight and powerful field validation library for Android.
Home Page: https://wellingtoncosta.github.io/convalida
License: Apache License 2.0
This feature will able Convalida to apply the validations using a Kotlin DSL that will be must defined. This will generate an artifact called convalida-ktx
.
Maybe this will turn possible to use Convalida with Anko #23.
Hi,
Any ideas on how to plug it with Kotlin Anko library? I tend to use it and skip data binding, so not sure how I'd put the annotations.
This feature will provide a mechanism for developers to create their own custom validations. A developer must write custom annotations and its validator classes.
This issue aims to eliminate the reflection code to find and instantiate the generated classes.
Currently, when the Convalida.init(this)
is called, internally the library uses reflection to find and instantiate the generated classes for fields validation. It's not a good practice in Android.
After this implementation, probably the Convalida.init(this)
will no longer be necessary.
last char is missed in
annotationProcesso. "r"
I got the following compile error when I tried to update to the version 3.2.0
of the library.
I don't use data-binding and I tried with both version 1.3.41
and 1.3.50
of the kotlin plugin. I tried also to set android.databinding.enableV2=false
in gradle.properties
to no avail
[kapt] An exception occurred: java.lang.NullPointerException
at convalida.compiler.ProcessingOptions.isDatabindingEnabled(ProcessingOptions.java:34)
at convalida.compiler.util.JavaFiler.cookJava(JavaFiler.java:104)
at convalida.compiler.ConvalidaProcessor.process(ConvalidaProcessor.java:184)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1068)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:79)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:35)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.runAnnotationProcessing(Kapt3Extension.kt:224)
at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:187)
at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:98)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:97)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:82)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:557)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:82)
at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:107)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:548)
at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:177)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:165)
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:55)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:84)
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:42)
at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:104)
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1558)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
When I click "Download sources" while looking through your library code Android Studio says sources cannot be found. It'd be very helpful if they were.
Just my 5 cents. Users actually don't want words "Invalid email!" come screaming at them when they just typed 1 letter.
It would be great if there'd be a way to support validate-on-unfocus pattern.
clearValidations()
just clears errors on text inputs, but if user adds/removes any letter the error appears again, which is not always wanted behaviour.
There should be way to fully unregister validation set so text input won't trigger any error on edit.
This feature will provide annotations to validate selectable fields, such as checkboxes and radio groups.
I would like to hear your opinion @emanuelet, @Kaio-Henrique, @itscorey.
Another option for validation is delayed one. Say, if I write 10 letters and suddenly stop writing them, the validation can chime in and mark field to be invalid.
Hi!
Another suggetion for your lib is validation for numeric valeu limit.
example:
min_value = 1
max_value = 100
If validation actually passed it'd be great to see green field.
This can be anything - "ok" mark or tick or check symbol.
Hello @wellingtoncosta,
Another improvement could be the validation of difference between two fields.
Ex.:
difference = incial distance - final distance, where incial distance can not be bigger than final distance.
Regards,
Just wanted to say thanks for your project. It's actually helpful and modern.
You can close this issue right away.
Pass a list of invalid fields as a method parameter that is annotated with @OnValidationError
.
First the project compiles with the following dependencies.
compile 'com.github.WellingtonCosta:convalida:1.3.4'
annotationProcessor 'com.github.WellingtonCosta.convalida:convalida-compiler:1.3.4'
Second of all, when I try to run the project I get the errors:
Error:java.lang.IllegalAccessException: no such method: convalida.compiler.ConvalidaProcessor.lambda$parseValidateOnClick$0(Element)boolean/invokeStatic
Error:java.lang.NoClassDefFoundError: com/sun/tools/javac/tree/JCTree$Visitor
Error:java.lang.ClassNotFoundException: Class com.sun.tools.javac.tree.JCTree$Visitor not found
Hello @wellingtoncosta,
One more suggestion heheheh
Something like this:
https://gist.github.com/AllanHasegawa/018ecd88605d7003c66fba89dfca8166
Hey @wellingtoncosta ,
You could enhance you validations making them to validate fields, but not require the validation when field is blank, for example validate an e-mail but let users save the field if it is blank.
This feature will improve the way that developers execute and manipulate validations, making the code cleaner through annotations.
New annotations:
@ValidateOnClick
@ClearValidationsOnClick
@OnValidationSuccess
@OnValidationError
The ValidateOnClick annotation must be mapped to a Button element, that will add a OnClickListener event to the button and will execute validateFields() method of ConvalidaValiddator class.
The ClearValidationsOnClick annotation must be mapped to a Button element, that will add a OnClickListener event to the button and will execute clearValidations() method of ConvalidaValiddator class.
The OnValidationSuccess annotation must be mapped to a method that will be executed if the all validations will be passed.
The OnValidationError annotation must be mapped to a method that will be executed if some field is not valid.
Example:
public class SampleActivity extends AppCompatActivity {
@NotEmptyValidation(R.string.field_required)
TextInputLayout nameLayout;
@EmailValidation(R.string.invalid_email)
TextInputLayout emailLayout;
@OnlyNumberValidation(R.string.only_numbers)
TextInputLayout ageLayout;
@ValidateOnClick
Button validateButton;
@ClearValidationsOnClick
Button clearValidationsButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
Convalida.init(this);
}
@OnValidationSuccess
public void onValidationSuccess() {
// Code ...
}
@OnValidationError
public void onValidationError() {
// Code ...
}
}
Add autoDismiss
parameter in annotations.
Example:
@NotEmptyValidation(errorMessage=R.string.field_required, autoDismiss=true)
EditText nameField;
I am using kotlin DSL for validation. I have multiple fragments opening after one another for user input. Each fragment has validation using code:
Sample code
private val validations by lazy {
validationSet(
validations = listOf(
binding.txtSomething.isRequired(errorMessage = getString(R.string.field_required))
),
actions = actions
validateByClickingOn binding.btnNext
whenOnSuccess ::onValidationSuccess
)
}
If I press the back button in between, validation stops working.
Observations:
apply { validations }
gets called once again once user comes back on fragmentvalidateByClickingOn binding.btnNext
whenOnSuccess ::onValidationSucces
does not get called second timeThis feature will provides support to use the validations by databinding.
Hello @wellingtoncosta,
Does your library support CPF(Brazil personal number) validation?
If not, it would be awesome to have this available in your library.
Thanks,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.