Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom error message in all rules for view extension methods #26

Closed
wajahatkarim3 opened this Issue Oct 15, 2018 · 8 comments

Comments

Projects
None yet
2 participants
@wajahatkarim3
Copy link
Owner

wajahatkarim3 commented Oct 15, 2018

In the view_ktx package, there are few classes for view extensions such as EditTextKtx.kt, TextViewKtx.kt etc. These classes contains kotlin extension methods of validation rules for respective Views.

For example, EditTextKtx.kt for NonEmptyRule check, we have two methods (one normal, and other with callback) like:

fun EditText.nonEmpty() : Boolean
{
    return validator().nonEmpty().check()
}

fun EditText.nonEmpty(callback: (message: String) -> Unit) : Boolean
{
    return validator().nonEmpty()
            .addErrorCallback {
                callback.invoke(it)
            }
            .check()
}

Task
The goal of this task is to add a Nullable parameter with name errorMsg in each of these methods and pass it in the validation check in the method definition like this:

fun EditText.nonEmpty(errorMsg:String? = null) : Boolean
{
    return validator().nonEmpty(errorMsg).check()
}

fun EditText.nonEmpty(callback: (message: String) -> Unit, errorMsg:String? = null) : Boolean
{
    return validator().nonEmpty(errorMsg)
            .addErrorCallback {
                callback.invoke(it)
            }
            .check()
}

Please note that how I have passed the errorMsg paramter in the checks of validator() inside the method definitions.

This should be done for all methods of 5 classes inside view_ktx package:

@emaiax

This comment has been minimized.

Copy link
Contributor

emaiax commented Oct 30, 2018

Also, I would like to have all validations checked at once instead of checking if all fields are validated one by one, since the validate method instantly breaks the loop if the first check returns false.

What a failFast: Boolean = true option? It makes sense @wajahatkarim3? I'd be happy to contribute for that.

@wajahatkarim3

This comment has been minimized.

Copy link
Owner Author

wajahatkarim3 commented Oct 30, 2018

Thanks @emaiax for the great suggestion. Yes I would love your contributions. 😄

@emaiax

This comment has been minimized.

Copy link
Contributor

emaiax commented Oct 30, 2018

After a whole day trying to setup the project, I'm unable to even run basic example tests without commenting the code or deleting .idea | .gradle folders. I'm using IntelliJ w/ Android Support.

Can you improve README with development instructions @wajahatkarim3? 🙏

@wajahatkarim3

This comment has been minimized.

Copy link
Owner Author

wajahatkarim3 commented Oct 31, 2018

Oh I am so sorry @emaiax for the trouble you had with setting up the library. Well, I haven't tried it on IntelliJ but I think I should delete the .idea | .gradle directories from the Github repo.

Thank you for letting me know 👍

@emaiax

This comment has been minimized.

Copy link
Contributor

emaiax commented Oct 31, 2018

Yeah, it didn't work either. I'm having a few issues with anottation-support versions.. had to comment code and then, no specs were being found to be run.

I'll try this out on Android Studio. I'll check back with you later.

@emaiax

This comment has been minimized.

Copy link
Contributor

emaiax commented Nov 1, 2018

Hi @wajahatkarim3. I've installed Android Studio, build the project from scratch and BOOM. Same issue. I'll move the conversation to #29. tks!

@wajahatkarim3

This comment has been minimized.

Copy link
Owner Author

wajahatkarim3 commented Nov 1, 2018

Hello @emaiax
Thank you for taking time to fix these issues. I just found the problem. It was caused after the merging of pull request #27 and some of my own code commits. I am fixing this and adding few new commits on master branch. I will let you know real quick once its done. 👍

wajahatkarim3 added a commit that referenced this issue Nov 1, 2018

wajahatkarim3 added a commit that referenced this issue Nov 1, 2018

Merge pull request #30 from wajahatkarim3/compiler_error_branch
Adds custom error messages fro all rules for view extension methods. Fixes issue #26 and issue #29
@wajahatkarim3

This comment has been minimized.

Copy link
Owner Author

wajahatkarim3 commented Nov 1, 2018

@emaiax I have fixed the compile errors and also finished this issue. So, I am closing this issue and also issue #29 as that was also part of this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.