function assignment_fapi_validation_rules() {
return array(
'char_1000' => array(
'callback' => 'assignment_view_own_validation_rule_name',
'error_msg' => 'Not more than 1000 characters',
),
'check_user' => array(
'callback' => 'assignment_validation_check_empty',
'error_msg' => t('%field cannot be empty'),
),
);
}
function assignment_view_own_validation_rule_name($value) {
if (strlen($value) <= 1000) {
return TRUE;
} else {
return FALSE;
}
}
function assignment_validation_check_empty($value) {
//if($_SERVER['REMOTE_ADDR'] == '192.168.99.180'){
// echopre($value); exit; }
if(empty($value)) {
return FALSE;
}
else {
return TRUE;
}
}
function assignment_clientside_validation_rule_alter(&$js_rules, $element, $context) {
switch ($context['type']) {
case 'fapi':
if ($context['rule']['callback'] == 'assignment_view_own_validation_rule_name') {
_assignment_set_number($element['#name'], $element['#title'], $decimalpoint, &$js_rules);
}
break;
if ($context['rule']['callback'] == 'assignment_validation_check_empty') {
_assignment_set_empty($element['#name'], $element['#title'], $decimalpoint, &$js_rules);
}
break;
}
}
function _assignment_set_number($name, $title, $decimalpoint, &$js_rules) {
drupal_add_js(drupal_get_path('module', 'assignment') . '/js/assignment_validation.js');
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$js_rules[$name]['chars_count'] = TRUE;
$js_rules[$name]['messages']['chars_count'] = t('You Use only 1000 characters at !field.', array('!field' => $title));
}
function _assignment_set_empty($name, $title, $decimalpoint, &$js_rules){
//if($_SERVER['REMOTE_ADDR'] == '192.168.99.180'){
// echopre($name); exit; }
drupal_add_js(drupal_get_path('module', 'assignment') . '/js/assignment_validation.js');
$title = variable_get('clientside_validation_prefix', '') . $title . variable_get('clientside_validation_suffix', '');
$js_rules[$name]['user_check'] = TRUE;
$js_rules[$name]['messages']['user_check'] = t('Must Enter a value in !field.', array('!field' => $title));
}
" This function not working...."
" This is .js file...."
Drupal.behaviors.imorphFormBehavior = function (context) {
//Add an eventlistener to the document reacting on the
//'clientsideValidationAddCustomRules' event.
$(document).bind('clientsideValidationAddCustomRules', function(event){
//Add your custom method with the 'addMethod' function of jQuery.validator
//http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethod...
jQuery.validator.addMethod("chars_count", function(value, element, param) {
//let an element match an exact value defined by the user
var intRegex = /^.{0,1000}$/;
return intRegex.test(value);
//return value == param;
//Enter a default error message, numbers between {} will be replaced
//with the matching value of that key in the param array, enter {0} if
//param is a value and not an array.
}, jQuery.format('Value must enter only 1000 jquery'));
jQuery.validator.addMethod("check", function(value, element, param) {
//alert(value);
//alert(element);
//alert(param);
if (!value) {
return false;
}
else {
return true;
}
}, jQuery.format('Value must enter only integer jquery'));
jQuery.validator.addMethod("user_check", function(value, element, param) {
alert(value);
if (!value) {
return false;
}
else {
return true;
}
}, jQuery.format('Value must enter only integer jquery'));
jQuery.validator.addMethod("check_community", function(value, element, param) {
//alert('aaa');
if(!value) {
return true;
}
else {
return false;
}
}, jQuery.format(''));
//jQuery.validator.addMethod("communities_check", function(value, element, param) {
// alert('Hiii');
// //alert(element);
// //alert(param);
// if(!value) {
// return false;
// }
// else{
//
// return true;
// }
//}, jQuery.format('Value must enter only integer jquery'));
});
//jQuery.event.trigger('clientsideValidationAddCustomRules');
}