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

fixes validator parameters allowing spaces in them #1213

Closed
wants to merge 2 commits into from
Closed

fixes validator parameters allowing spaces in them #1213

wants to merge 2 commits into from

Conversation

kulbakin
Copy link
Contributor

The pull request allows validator parameters specified in data-validators attribute (or legacy class) after validator name to have spaces in their values, e.g.

<input type="radio" name="primary_category" data-validators="validate-reqchk-byname label:'primary category'" />
...

@SergioCrisostomo
Copy link
Member

I think this is a valid fix, although Docs say:

Note that string values that require spaces should use URL encoding, as spaces are the delimiters for validator names. Then your validator should url decode them from the data-validator-properites object when it uses them. Alternately, you can store this data directly on the input:

Could you add some spec to the PR like:

it('should get the properties from string with spaces', function(){
    var input = new Element('input', {'data-validators': 'label:\'primary category\''});
    expect(input.get('validatorProps')).toEqual({label: "primary category"});
});

They should go here, in the /Specs/Forms/Form.Validator.js file.

@kulbakin
Copy link
Contributor Author

@SergioCrisostomo added spec as suggested

@anutron
Copy link
Member

anutron commented Oct 27, 2015

Good stuff. We should update the documentation for it. Update docs and ship it.

@SergioCrisostomo
Copy link
Member

merged/fixed in 8ce4ade

@effetb
Copy link

effetb commented Aug 26, 2016

Hi,
It is not working if there is more than one space in the value.
Ex. : data-validators="validate-match matchInput:'password' matchName:'your new password'"

It give me "undefined" instead of "your new password"
Mootools Core : version: '1.6.0', build: '529422872adfff401b901b8b6c7ca5114ee95e2b'
Mootools More : version: '1.6.0', build: '45b71db70f879781a7e0b0d3fb3bb1307c2521eb'

I suggest to modify the second return call in this code :

Element.Properties.validators = {

    get: function(){
        return (this.get('data-validators') || this.className).clean().replace(/'(\\.|[^'])*'|"(\\.|[^"])*"/g, function(match){
            return match.replace(' ', '\\x20');
        }).split(' ');
    }

};

by this

Element.Properties.validators = {

    get: function(){
        return (this.get('data-validators') || this.className).clean().replace(/'(\\.|[^'])*'|"(\\.|[^"])*"/g, function(match){
               return match.split(' ').join('\\x20');
        }).split(' ');
    }

};

Regards

@kulbakin
Copy link
Contributor Author

indeed, or it could be

return match.replace(/ /g, '\\x20');

@effetb
Copy link

effetb commented Aug 26, 2016

Yes you are right.

@kulbakin kulbakin deleted the form-validator-fix branch September 11, 2016 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants