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 rule methods in Validator class #24

Closed
wajahatkarim3 opened this Issue Oct 14, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@wajahatkarim3
Copy link
Owner

wajahatkarim3 commented Oct 14, 2018

Every Rule class such as NonEmptyRule has a variable errorMsg in the constructor with a pre-defined value which is returned as the error message when validation is failed.

For example, in NonEmptyRule

class NonEmptyRule(var errorMsg: String = "Can't be empty!") : BaseRule

Also, in Validator class, each rule has a method for quick validation like this for NonEmptyRule:

fun nonEmpty() : Validator
{
    addRule(NonEmptyRule())
    return this
}

Task
The goal of this task is to add error messages in all the rule methods of Validator class like this:

fun nonEmpty(errorMsg: String = "Can't be empty!") : Validator
{
    addRule(NonEmptyRule(errorMsg))
    return this
}

Please note that there's an errorMsg variable has been passed in the rule method now with a pre-defined value. This value should be copied from the passed rule (here NonEmptyRule).

@renanrbs

This comment has been minimized.

Copy link
Contributor

renanrbs commented Oct 14, 2018

hey @wajahatkarim3, the messages shoud be duplicated on the validator class? isnt this going to make things harder if the message needs to be changed? Especially because the project is not internationalized yet

@wajahatkarim3

This comment has been minimized.

Copy link
Owner Author

wajahatkarim3 commented Oct 14, 2018

That's really good point. I didn't think about it. Well the purpose is to add functionality which can allow developers to customize message. How about we overload each rule method in Validator class like this:

fun nonEmpty(errorMsg: String) : Validator
{
 addRule(NonEmptyRule(errorMsg)) 
return this
}

wajahatkarim3 added a commit that referenced this issue Oct 15, 2018

Merge pull request #25 from renanrbs/issue-24
Add custom error message in all rule methods in Validator class. Fixes issue #24
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.