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

Allow for initialising validator with localizedViolationString #61

Open
markst opened this issue May 5, 2017 · 2 comments
Open

Allow for initialising validator with localizedViolationString #61

markst opened this issue May 5, 2017 · 2 comments

Comments

@markst
Copy link

markst commented May 5, 2017

It would be nice if it were easier to update the localizedViolationString when initialising a violation object.

For example I currently have an extension on Validator which allows me to initialise with a violationString.

extension Validator {
    public init(violationString: String) {
        self.init()
        var condition = self.conditions.first!
        condition.localizedViolationString = violationString
        conditions = [condition]
    }
}

Which makes creating a form much easier when I have multiple strings per field:

self.controlForm.addField(passwordTextField, validator: PresentValidator(violationString: "Please enter your password"))
@markst markst changed the title Allow for easier updating of localizedViolationString Allow for initialising validator with localizedViolationString May 5, 2017
@ghost
Copy link

ghost commented May 12, 2017

This is a good suggestion. Although it'd be preferred if this was an optional parameter with a default of nil so that way if none is passed in through the initializer, the default localized violation string is used. This way you don't need to have more than one init and continues to maintain API stability in the framework.

If you'd like to raise a PR for this enhancement, we'd love to review it!

@ghost ghost added the enhancement label May 12, 2017
@markst
Copy link
Author

markst commented May 25, 2017

Sounds good. I'll PR once I get the chance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant