| 6 | | $options = $obj->getOptions(); |
|---|
| 7 | | $js = ''; |
|---|
| 8 | | if($options['required']) |
|---|
| 9 | | { |
|---|
| 10 | | $js .= 'required: true, '; |
|---|
| 11 | | } |
|---|
| 12 | | if($options['max_length']) |
|---|
| 13 | | { |
|---|
| 14 | | $js .= 'maxlength: ' . $options['max_length'] . ', '; |
|---|
| 15 | | } |
|---|
| 16 | | if($options['min_length']) |
|---|
| 17 | | { |
|---|
| 18 | | $js .= 'minlength: ' . $options['min_length'] . ', '; |
|---|
| 19 | | } |
|---|
| 20 | | if(strlen($js) > 0) |
|---|
| 21 | | { |
|---|
| 22 | | $js = substr($js, 0, strlen($js) - 2); |
|---|
| 23 | | } |
|---|
| | 6 | return sf_validator_standard_validator_rules($obj); |
|---|
| | 7 | } |
|---|
| | 8 | |
|---|
| | 9 | function sfValidatorRegex_rules($obj) |
|---|
| | 10 | { |
|---|
| | 11 | $options = $obj->getOptions(); |
|---|
| | 12 | $js = ''; |
|---|
| | 13 | $js .= 'regex: ' . $options['pattern'] . ', '; |
|---|
| | 14 | $js .= sf_validator_add_generic_rules($options); |
|---|
| | 15 | $js = sf_validator_trim_js_string($js); |
|---|
| 32 | | if($options['required']) |
|---|
| 33 | | { |
|---|
| 34 | | $js .= 'required: true, '; |
|---|
| 35 | | } |
|---|
| 36 | | if(strlen($js) > 0) |
|---|
| 37 | | { |
|---|
| 38 | | $js = substr($js, 0, strlen($js) - 2); |
|---|
| 39 | | } |
|---|
| 40 | | return $js; |
|---|
| | 24 | $js .= sf_validator_add_generic_rules($options); |
|---|
| | 25 | $js = sf_validator_trim_js_string($js); |
|---|
| | 26 | return $js; |
|---|
| | 27 | } |
|---|
| | 28 | |
|---|
| | 29 | function sfValidatorUrl_rules($obj) |
|---|
| | 30 | { |
|---|
| | 31 | $options = $obj->getOptions(); |
|---|
| | 32 | $js = ''; |
|---|
| | 33 | $js .= 'url: true, '; |
|---|
| | 34 | $js .= sf_validator_add_generic_rules($options); |
|---|
| | 35 | $js = sf_validator_trim_js_string($js); |
|---|
| | 36 | return $js; |
|---|
| | 37 | } |
|---|
| | 38 | |
|---|
| | 39 | function sfValidatorInteger_rules($obj) |
|---|
| | 40 | { |
|---|
| | 41 | $options = $obj->getOptions(); |
|---|
| | 42 | $js = ''; |
|---|
| | 43 | $js .= 'digits: true, '; |
|---|
| | 44 | $js .= sf_validator_add_generic_rules($options); |
|---|
| | 45 | $js = sf_validator_trim_js_string($js); |
|---|
| | 46 | return $js; |
|---|
| | 47 | } |
|---|
| | 48 | |
|---|
| | 49 | function sfValidatorPropelChoice_rules($obj) |
|---|
| | 50 | { |
|---|
| | 51 | return sf_validator_standard_validator_rules($obj); |
|---|
| | 52 | } |
|---|
| | 53 | |
|---|
| | 54 | function sfValidatorDoctrineChoice_rules($obj) |
|---|
| | 55 | { |
|---|
| | 56 | return sf_validator_standard_validator_rules($obj); |
|---|
| | 69 | $js .= sf_validator_add_generic_rules($options); |
|---|
| | 70 | $js = sf_validator_trim_js_string($js); |
|---|
| | 71 | return $js; |
|---|
| | 72 | } |
|---|
| | 73 | |
|---|
| | 74 | function sf_validator_standard_validator_rules($obj) |
|---|
| | 75 | { |
|---|
| | 76 | $options = $obj->getOptions(); |
|---|
| | 77 | $js = ''; |
|---|
| | 78 | $js .= sf_validator_add_generic_rules($options); |
|---|
| | 79 | $js = sf_validator_trim_js_string($js); |
|---|
| | 80 | return $js; |
|---|
| | 81 | } |
|---|
| | 82 | |
|---|
| | 83 | function sf_validator_add_generic_rules($options) |
|---|
| | 84 | { |
|---|
| | 85 | $js = ''; |
|---|
| | 86 | if($options['required']) |
|---|
| | 87 | { |
|---|
| | 88 | $js .= 'required: true, '; |
|---|
| | 89 | } |
|---|
| | 90 | if(isset($options['max_length'])) |
|---|
| | 91 | { |
|---|
| | 92 | $js .= 'maxlength: ' . $options['max_length'] . ', '; |
|---|
| | 93 | } |
|---|
| | 94 | if(isset($options['min_length'])) |
|---|
| | 95 | { |
|---|
| | 96 | $js .= 'minlength: ' . $options['min_length'] . ', '; |
|---|
| | 97 | } |
|---|
| | 98 | return $js; |
|---|
| | 99 | } |
|---|
| | 100 | |
|---|
| | 101 | function sf_validator_trim_js_string($js) |
|---|
| | 102 | { |
|---|
| | 103 | if(strlen($js) > 0) |
|---|
| | 104 | { |
|---|
| | 105 | $js = substr($js, 0, strlen($js) - 2); |
|---|
| | 106 | } |
|---|
| | 107 | return $js; |
|---|
| | 108 | } |
|---|
| | 109 | |
|---|
| | 110 | /* messages */ |
|---|
| | 111 | function sf_form_messages($obj, $fieldname) |
|---|
| | 112 | { |
|---|
| | 113 | $js = ''; |
|---|
| | 114 | $options = $obj->getOptions(); |
|---|
| | 115 | $messages = $obj->getMessages(); |
|---|
| | 116 | //dev::pr($options); |
|---|
| | 117 | //dev::pr($messages, true); |
|---|
| | 158 | |
|---|
| | 159 | // replace the placeholder with the field value |
|---|
| | 160 | if(strpos($messages[$key], '%value%') !== false) |
|---|
| | 161 | { |
|---|
| | 162 | $messages[$key] = str_replace('%value%', "' + $('[name=\"" . $fieldname . "\"]').val() + '", $messages[$key]); |
|---|
| | 163 | } |
|---|
| | 164 | |
|---|
| | 165 | $keytext = $key; |
|---|
| | 166 | switch(get_class($obj)) |
|---|
| | 167 | { |
|---|
| | 168 | |
|---|
| | 169 | case 'sfValidatorRegex': |
|---|
| | 170 | $keytext = str_replace('invalid', 'regex', $keytext); |
|---|
| | 171 | break; |
|---|
| | 172 | |
|---|
| | 173 | case 'sfValidatorUrl': |
|---|
| | 174 | $keytext = str_replace('invalid', 'url', $keytext); |
|---|
| | 175 | break; |
|---|
| | 176 | |
|---|
| | 177 | case 'sfValidatorInteger': |
|---|
| | 178 | $keytext = str_replace('invalid', 'digits', $keytext); |
|---|
| | 179 | break; |
|---|
| | 180 | |
|---|
| | 181 | case 'sfValidatorDate': |
|---|
| | 182 | $keytext = str_replace('bad_format', $date_method, $keytext); |
|---|
| | 183 | break; |
|---|
| | 184 | |
|---|
| | 185 | } |
|---|