Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
clientside_validation
Commits
6e8fa242
Commit
6e8fa242
authored
Feb 24, 2014
by
jelles
Browse files
Merge branch '7.x-1.x' of git.drupal.org:project/clientside_validation into 7.x-1.x
parents
ac3318b1
83aaeb35
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
24 deletions
+132
-24
clientside_validation.install
clientside_validation.install
+49
-1
clientside_validation.js
clientside_validation.js
+61
-7
clientside_validation.module
clientside_validation.module
+19
-13
clientside_validation_form/clientside_validation_form.module
clientside_validation_form/clientside_validation_form.module
+1
-1
clientside_validation_testswarm/clientside_validation_testswarm.install
...idation_testswarm/clientside_validation_testswarm.install
+2
-2
No files found.
clientside_validation.install
View file @
6e8fa242
...
...
@@ -119,7 +119,54 @@ function clientside_validation_update_7100() {
*/
function
clientside_validation_update_7101
()
{
if
(
!
db_table_exists
(
'clientside_validation_settings'
))
{
db_create_table
(
'clientside_validation_settings'
,
drupal_get_schema
(
'clientside_validation_settings'
,
TRUE
));
$schema
[
'clientside_validation_settings'
]
=
array
(
'description'
=>
'Table for storing Clientside Validation Settings'
,
'fields'
=>
array
(
'cvsid'
=>
array
(
'description'
=>
'The primary identifier for the clientside validation settings'
,
'type'
=>
'serial'
,
'unsigned'
=>
TRUE
,
'not null'
=>
TRUE
,
),
'type'
=>
array
(
'description'
=>
'The type of setting: content_type, webform or custom'
,
'type'
=>
'varchar'
,
'length'
=>
32
,
'not null'
=>
TRUE
,
'default'
=>
''
,
),
'status'
=>
array
(
'description'
=>
'The status for this form. 1 for enabled (validate), 0 for disabled (don\'t validate)'
,
'type'
=>
'int'
,
'not null'
=>
TRUE
,
'default'
=>
0
,
'size'
=>
'tiny'
,
),
'form_id'
=>
array
(
'description'
=>
'The form id these settings apply to'
,
'type'
=>
'varchar'
,
'length'
=>
255
,
'not null'
=>
TRUE
,
'default'
=>
''
,
),
'settings'
=>
array
(
'type'
=>
'blob'
,
'not null'
=>
TRUE
,
'size'
=>
'big'
,
'translatable'
=>
TRUE
,
),
),
'indexes'
=>
array
(
'clientside_validation_settings_form_id'
=>
array
(
'form_id'
),
'clientside_validation_settings_type'
=>
array
(
'type'
),
'clientside_validation_settings_form_id_type'
=>
array
(
'form_id'
,
'type'
),
),
'unique keys'
=>
array
(
'cvs_form_id'
=>
array
(
'form_id'
),
),
'primary key'
=>
array
(
'cvsid'
),
);
db_create_table
(
'clientside_validation_settings'
,
$schema
[
'clientside_validation_settings'
]);
}
// @TODO: Convert old settings to new
// 1. fill in clientside_validation_default_settings
...
...
@@ -276,6 +323,7 @@ function clientside_validation_update_7103() {
// Nothing to do here.
return
;
}
module_load_include
(
'module'
,
'clientside_validation'
,
'clientside_validation'
);
$default_settings
=
clientside_validation_settings_load_defaults
();
if
(
!
isset
(
$default_settings
[
'validate_options'
][
'captcha'
]))
{
$default_settings
[
'validate_options'
][
'captcha'
]
=
1
;
...
...
clientside_validation.js
View file @
6e8fa242
...
...
@@ -707,17 +707,34 @@
jQuery
.
each
(
self
.
forms
[
formid
].
checkboxrules
,
function
(
r
)
{
var
$checkboxes
=
$form
.
find
(
this
.
checkboxgroupminmax
[
2
]).
find
(
'
input[type="checkbox"]
'
);
if
(
$checkboxes
.
length
)
{
$checkboxes
.
addClass
(
'
require-one
'
);
var
identifier
=
'
require-one-
'
+
this
.
checkboxgroupminmax
[
2
].
substring
(
1
);
var
min
=
this
.
checkboxgroupminmax
[
0
];
var
message
=
this
.
messages
.
checkboxgroupminmax
;
$checkboxes
.
addClass
(
identifier
);
$checkboxes
.
each
(
function
(){
var
$checkbox
=
$
(
this
);
var
rule
=
self
.
forms
[
formid
].
checkboxrules
[
r
];
if
(
typeof
self
.
validators
[
formid
].
settings
.
messages
[
r
]
===
'
undefined
'
)
{
self
.
validators
[
formid
].
settings
.
messages
[
r
]
=
{};
var
newrule
=
{
require_from_group
:
[
min
,
'
.
'
+
identifier
]
}
$
.
extend
(
self
.
validators
[
formid
].
settings
.
messages
[
r
],
rule
.
messages
);
delete
rule
.
messages
;
$
(
this
).
rules
(
"
add
"
,
rule
);
$
(
this
).
change
(
hideErrordiv
);
$checkbox
.
rules
(
"
add
"
,
newrule
);
$checkbox
.
change
(
hideErrordiv
);
if
(
typeof
self
.
validators
[
formid
].
settings
.
messages
[
$checkbox
.
attr
(
'
name
'
)]
===
'
undefined
'
)
{
self
.
validators
[
formid
].
settings
.
messages
[
$checkbox
.
attr
(
'
name
'
)]
=
{};
}
$
.
extend
(
self
.
validators
[
formid
].
settings
.
messages
[
$checkbox
.
attr
(
'
name
'
)],
{
require_from_group
:
message
});
});
if
(
typeof
self
.
validators
[
formid
].
settings
.
messages
[
'
.
'
+
identifier
]
===
'
undefined
'
)
{
self
.
validators
[
formid
].
settings
.
messages
[
'
.
'
+
identifier
]
=
{};
}
$
.
extend
(
self
.
validators
[
formid
].
settings
.
messages
[
'
.
'
+
identifier
],
{
require_from_group
:
message
});
console
.
log
(
self
.
validators
[
formid
].
settings
.
messages
);
}
});
self
.
time
.
stop
(
'
checkboxrules
'
);
...
...
@@ -806,6 +823,21 @@
return
this
.
optional
(
element
)
||
/^-
?(?:\d
+|
\d{1,3}(?:\.\d{3})
+
)(?:
,
\d
+
)?
$/
.
test
(
value
);
});
jQuery
.
validator
.
addMethod
(
"
min_comma
"
,
function
(
value
,
element
,
param
)
{
var
real_val
=
Number
(
value
.
replace
(
'
,
'
,
'
.
'
));
return
this
.
optional
(
element
)
||
real_val
>=
param
;
});
jQuery
.
validator
.
addMethod
(
"
max_comma
"
,
function
(
value
,
element
,
param
)
{
var
real_val
=
Number
(
value
.
replace
(
'
,
'
,
'
.
'
));
return
this
.
optional
(
element
)
||
real_val
<=
param
;
});
jQuery
.
validator
.
addMethod
(
"
range_comma
"
,
function
(
value
,
element
,
param
)
{
var
real_val
=
Number
(
value
.
replace
(
'
,
'
,
'
.
'
));
return
this
.
optional
(
element
)
||
(
real_val
>=
param
[
0
]
&&
real_val
<=
param
[
1
]);
});
// Min a and maximum b checkboxes from a group
jQuery
.
validator
.
addMethod
(
"
checkboxgroupminmax
"
,
function
(
value
,
element
,
param
)
{
var
amountChecked
=
$
(
param
[
2
]).
find
(
'
input:checked
'
).
length
;
...
...
@@ -1335,6 +1367,28 @@
}
},
jQuery
.
format
(
'
Not a valid EAN number.
'
));
jQuery
.
validator
.
addMethod
(
"
require_from_group
"
,
function
(
value
,
element
,
options
)
{
var
$fields
=
$
(
options
[
1
],
element
.
form
),
$fieldsFirst
=
$fields
.
eq
(
0
),
validator
=
$fieldsFirst
.
data
(
"
valid_req_grp
"
)
?
$fieldsFirst
.
data
(
"
valid_req_grp
"
)
:
$
.
extend
({},
this
),
isValid
=
$fields
.
filter
(
function
()
{
return
validator
.
elementValue
(
this
);
}).
length
>=
options
[
0
];
// Store the cloned validator for future validation
$fieldsFirst
.
data
(
"
valid_req_grp
"
,
validator
);
// If element isn't being validated, run each require_from_group field's validation rules
if
(
!
$
(
element
).
data
(
"
being_validated
"
))
{
$fields
.
data
(
"
being_validated
"
,
true
);
$fields
.
each
(
function
()
{
validator
.
element
(
this
);
});
$fields
.
data
(
"
being_validated
"
,
false
);
}
return
isValid
;
},
jQuery
.
validator
.
format
(
"
Please fill at least {0} of these fields.
"
));
/**
* Allow other modules to add more rules.
* @event clientsideValidationAddCustomRules
...
...
clientside_validation.module
View file @
6e8fa242
...
...
@@ -580,64 +580,67 @@ function _clientside_validation_set_number_decimal($name, $title, $decimalpoint,
/**
* Set validation rule for fields with a minimum and/or a maximum value.
*/
function
_clientside_validation_set_minmax
(
$name
,
$title
,
$min
,
$max
,
&
$js_rules
,
$message
=
''
)
{
function
_clientside_validation_set_minmax
(
$name
,
$title
,
$min
,
$max
,
&
$js_rules
,
$message
=
''
,
$decimal_separator
=
'.'
)
{
$title
=
_clientside_validation_set_title
(
$title
);
if
(
isset
(
$min
)
&&
$min
!==
''
&&
isset
(
$max
)
&&
$max
!==
''
)
{
$js_rules
[
$name
][
'range'
]
=
array
(
$min
,
$max
);
$rule
=
$decimal_separator
==
'.'
?
'range'
:
'range_comma'
;
$js_rules
[
$name
][
$rule
]
=
array
(
$min
,
$max
);
if
(
empty
(
$message
))
{
$variables
=
array
(
'message'
=>
'!title field has to be between !min and !max.'
,
'placeholders'
=>
array
(
'!title'
=>
$title
,
'!min'
=>
$min
,
'!max'
=>
$max
),
'error_type'
=>
'range'
,
'error_type'
=>
$rule
,
'element_name'
=>
$name
,
);
}
else
{
$variables
=
array
(
'message'
=>
$message
,
'error_type'
=>
'range'
,
'error_type'
=>
$rule
,
'element_name'
=>
$name
,
);
}
$js_rules
[
$name
][
'messages'
][
'range'
]
=
theme
(
'clientside_error'
,
$variables
);
$js_rules
[
$name
][
'messages'
][
$rule
]
=
theme
(
'clientside_error'
,
$variables
);
}
elseif
(
isset
(
$min
)
&&
$min
!==
''
)
{
$js_rules
[
$name
][
'min'
]
=
$min
;
$rule
=
$decimal_separator
==
'.'
?
'min'
:
'min_comma'
;
$js_rules
[
$name
][
$rule
]
=
$min
;
if
(
empty
(
$message
))
{
$variables
=
array
(
'message'
=>
'!title field has to be greater than !min.'
,
'placeholders'
=>
array
(
'!title'
=>
$title
,
'!min'
=>
$min
),
'error_type'
=>
'min'
,
'error_type'
=>
$rule
,
'element_name'
=>
$name
,
);
}
else
{
$variables
=
array
(
'message'
=>
$message
,
'error_type'
=>
'min'
,
'error_type'
=>
$rule
,
'element_name'
=>
$name
,
);
}
$js_rules
[
$name
][
'messages'
][
'min'
]
=
theme
(
'clientside_error'
,
$variables
);
$js_rules
[
$name
][
'messages'
][
$rule
]
=
theme
(
'clientside_error'
,
$variables
);
}
elseif
(
isset
(
$max
)
&&
$max
!==
''
)
{
$js_rules
[
$name
][
'max'
]
=
$max
;
$rule
=
$decimal_separator
==
'.'
?
'max'
:
'max_comma'
;
$js_rules
[
$name
][
$rule
]
=
$max
;
if
(
empty
(
$message
))
{
$variables
=
array
(
'message'
=>
'!title field has to be smaller than !max.'
,
'placeholders'
=>
array
(
'!title'
=>
$title
,
'!max'
=>
$max
),
'error_type'
=>
'max'
,
'error_type'
=>
$rule
,
'element_name'
=>
$name
,
);
}
else
{
$variables
=
array
(
'message'
=>
$message
,
'error_type'
=>
'max'
,
'error_type'
=>
$rule
,
'element_name'
=>
$name
,
);
}
$js_rules
[
$name
][
'messages'
][
'max'
]
=
theme
(
'clientside_error'
,
$variables
);
$js_rules
[
$name
][
'messages'
][
$rule
]
=
theme
(
'clientside_error'
,
$variables
);
}
}
...
...
@@ -1154,6 +1157,8 @@ function _clientside_validation_set_regex_pcre($name, $title, &$js_rules, $expre
* Set validation rule for file fields that must have a certain extension.
*/
function
_clientside_validation_set_extensions
(
$name
,
$extensions
,
&
$js_rules
)
{
// @see https://drupal.org/comment/8428631#comment-8428631
/*
$extension_list = preg_replace('#,(?![^,]+,)#', ' or', implode(', ', $extensions));
$js_rules[$name]['accept'] = implode('|', $extensions);
$variables = array(
...
...
@@ -1163,6 +1168,7 @@ function _clientside_validation_set_extensions($name, $extensions, &$js_rules) {
'element_name' => $name
);
$js_rules[$name]['messages']['accept'] = theme('clientside_error', $variables);
*/
}
/**
...
...
clientside_validation_form/clientside_validation_form.module
View file @
6e8fa242
...
...
@@ -107,7 +107,7 @@ function clientside_validation_regular($form_id, $element, &$js_rules, $form_sta
$max
=
$instance
[
'settings'
][
'max'
];
}
if
(
$min
!==
''
||
$max
!==
''
)
{
_clientside_validation_set_minmax
(
$el_name
,
$el_title
,
$min
,
$max
,
$js_rules
);
_clientside_validation_set_minmax
(
$el_name
,
$el_title
,
$min
,
$max
,
$js_rules
,
''
,
$field
[
'settings'
][
'decimal_separator'
]
);
}
if
(
isset
(
$field
[
'settings'
][
'decimal_separator'
]))
{
...
...
clientside_validation_testswarm/clientside_validation_testswarm.install
View file @
6e8fa242
...
...
@@ -8,7 +8,7 @@
/**
* Implements hook_uninstall().
*/
function
clientside_validation_uninstall
()
{
function
clientside_validation_
testswarm_
uninstall
()
{
variable_del
(
'clientside_validation_rules_added'
);
variable_del
(
'clientside_validation_testswarm_nodenames'
);
}
...
...
@@ -98,4 +98,4 @@ function clientside_validation_testswarm_update_7103() {
*/
function
clientside_validation_testswarm_update_7104
()
{
clientside_validation_testswarm_enable
();
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment