repocrypts / Validator

Client-side javascript validator library ports from Laravel 5.2
MIT License
46 stars 22 forks source link

Extend rules with multi-word names fail #38

Closed Jao-Quin closed 2 years ago

Jao-Quin commented 3 years ago

There's an inconsistency in the rule name parsing between extend method and parseItemRules. extend calls this.titleCase without the delimiter, so multiword rule names don't match the pattern expected by the rest of the code, e.g:

A rule called exists_in_data is saved as Exists_in_data (without delimiter) but the script expects ExistsInData (with delimiter).

I've fixed it on my end by overriding the extend method with one that calls titleCase using the delimiter:

    extend(ruleName, callback, customMessage) {
        this.customRules[this.titleCase(ruleName, '_')] = callback;

        if (customMessage) {
            this.customMessages[this.snakeCase(ruleName)] = customMessage;
        }
    }

Happy to do a pull request.