Skip to content

Commit 8ce4ade

Browse files
Merge branch 'pr1213', fix validator parameters allowing spaces in them
* pr1213: update doc: strings can have spaces add spec for the fix allowing spaces in validator params fixes validator parameters allowing spaces in them git cherry-pick a7342dc
2 parents fa1acb1 + 372aeda commit 8ce4ade

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

Docs/Forms/Form.Validator.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Form.Validator Method: Constructor
5454
### Notes
5555

5656
* [Form.Validator][] must be configured with [InputValidator][] objects (see below for details as well as a list of built-in validators). Each [InputValidator][] will be applied to any input that includes its name in the data-validators property within the elements of the form that match the fieldSelectors option.
57-
* The preferred method for passing in validator properties (like the minimum length) is to append the value after the name. This value will be passed through [JSON.decode][] so it can be a number, string, array representation, etc.
57+
* The preferred method for passing in validator properties (like the minimum length) is to append the value after the name. This value will be passed through [JSON.decode][] so it can be a number, string, array representation, etc. Quoted strings like `'foo'` can have spaces.
5858

5959
// the minimum length the user can supply is the integer 10
6060
<input data-validators="minLength:10" />

Source/Forms/Form.Validator.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ var InputValidator = this.InputValidator = new Class({
6969
Element.Properties.validators = {
7070

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

7577
};

Specs/Forms/Form.Validator.js

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ describe('Form.Validator', function(){
1919
expect(element.get('validatorProps')).toEqual({minLength: 10});
2020
});
2121

22+
it('should get the properties from string with spaces', function(){
23+
var input = new Element('input', {'data-validators': 'label:\'primary category\''});
24+
expect(input.get('validatorProps')).toEqual({label: "primary category"});
25+
});
26+
2227
it('should get the validator properties from a JSON string in the validatorProps attribute', function(){
2328
var element = new Element('input').setProperty('validatorProps', '{minLength: 10, maxLength:20}');
2429
expect(element.get('validatorProps')).toEqual({minLength: 10, maxLength: 20});

0 commit comments

Comments
 (0)