Commit fd355e41e5e8b3b950b0fc8c778b92607b6e8a49
1 parent
de00280f
Exists in
master
and in
5 other branches
correcoes_aderencia: Fields mark in red or green depending on the validation
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
2 changed files
with
33 additions
and
15 deletions
Show diff stats
public/mpog-user-validations.js
| @@ -186,7 +186,11 @@ | @@ -186,7 +186,11 @@ | ||
| 186 | }); | 186 | }); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | - function is_invalid_formated(text) { | 189 | + function invalid_name_validation(text) { |
| 190 | + if( text.trim().length == 0 ) { | ||
| 191 | + return true; | ||
| 192 | + } | ||
| 193 | + | ||
| 190 | var full_validation = /([^\w\*\s*])|(^|\s)([a-z]|[0-9])/; // no special chars and do not initialize with no capital latter | 194 | var full_validation = /([^\w\*\s*])|(^|\s)([a-z]|[0-9])/; // no special chars and do not initialize with no capital latter |
| 191 | var partial_validation = /[^\w\*\s*]/; // no special chars | 195 | var partial_validation = /[^\w\*\s*]/; // no special chars |
| 192 | text = replace_some_special_chars(text); | 196 | text = replace_some_special_chars(text); |
| @@ -207,8 +211,8 @@ | @@ -207,8 +211,8 @@ | ||
| 207 | } | 211 | } |
| 208 | 212 | ||
| 209 | // Generic | 213 | // Generic |
| 210 | - function show_plugin_error_message(field_id, hidden_message_id ) { | ||
| 211 | - var field = jQuery("#"+field_id); | 214 | + function show_plugin_error_message(field_selector, hidden_message_id ) { |
| 215 | + var field = jQuery(field_selector); | ||
| 212 | 216 | ||
| 213 | field.removeClass("validated").addClass("invalid"); | 217 | field.removeClass("validated").addClass("invalid"); |
| 214 | 218 | ||
| @@ -220,23 +224,28 @@ | @@ -220,23 +224,28 @@ | ||
| 220 | } | 224 | } |
| 221 | } | 225 | } |
| 222 | 226 | ||
| 223 | - function hide_plugin_error_message(field_id, hidden_message_id) { | ||
| 224 | - jQuery("#" + field_id).removeClass("invalid").addClass("validated"); | 227 | + function hide_plugin_error_message(field_selector, hidden_message_id) { |
| 228 | + jQuery(field_selector).removeClass("invalid").addClass("validated"); | ||
| 225 | jQuery("." + hidden_message_id).hide(); | 229 | jQuery("." + hidden_message_id).hide(); |
| 226 | } | 230 | } |
| 227 | - function addBlurFields(field_id, hidden_message_id, validation_function) { | ||
| 228 | - jQuery("#" + field_id).blur(function(){ | 231 | + |
| 232 | + function addBlurFields(field_selector, hidden_message_id, validation_function) { | ||
| 233 | + jQuery(field_selector).blur(function(){ | ||
| 229 | jQuery(this).attr("class", ""); | 234 | jQuery(this).attr("class", ""); |
| 230 | 235 | ||
| 231 | - if( this.value.length > 0 && validation_function(this.value) ) { | ||
| 232 | - show_plugin_error_message(field_id, hidden_message_id); | 236 | + if( validation_function(this.value) ) { |
| 237 | + show_plugin_error_message(field_selector, hidden_message_id); | ||
| 233 | } else { | 238 | } else { |
| 234 | - hide_plugin_error_message(field_id, hidden_message_id); | 239 | + hide_plugin_error_message(field_selector, hidden_message_id); |
| 235 | } | 240 | } |
| 236 | }); | 241 | }); |
| 237 | } | 242 | } |
| 238 | 243 | ||
| 239 | function invalid_email_validation(value) { | 244 | function invalid_email_validation(value) { |
| 245 | + if( value.trim().length == 0 ) { | ||
| 246 | + return true; | ||
| 247 | + } | ||
| 248 | + | ||
| 240 | var correct_format_regex = new RegExp(/^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/); | 249 | var correct_format_regex = new RegExp(/^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/); |
| 241 | 250 | ||
| 242 | return !correct_format_regex.test(value); | 251 | return !correct_format_regex.test(value); |
| @@ -285,10 +294,10 @@ | @@ -285,10 +294,10 @@ | ||
| 285 | fix_phone_mask_format("#profile_data_comercial_phone"); | 294 | fix_phone_mask_format("#profile_data_comercial_phone"); |
| 286 | fix_phone_mask_format("#profile_data_contact_phone"); | 295 | fix_phone_mask_format("#profile_data_contact_phone"); |
| 287 | 296 | ||
| 288 | - addBlurFields("profile_data_name", "full_name_error", is_invalid_formated); | ||
| 289 | - addBlurFields("profile_data_email", "email_error", invalid_email_validation); | ||
| 290 | - addBlurFields("user_secondary_email", "email_error", invalid_email_validation); | ||
| 291 | - addBlurFields("profile_data_personal_website", "site_error", invalid_site_validation); | ||
| 292 | - addBlurFields("profile_data_organization_website", "site_error", invalid_site_validation); | 297 | + addBlurFields("#profile_data_name", "full_name_error", invalid_name_validation); |
| 298 | + addBlurFields("#profile_data_email", "email_error", invalid_email_validation); | ||
| 299 | + addBlurFields("#user_secondary_email", "email_error", invalid_email_validation); | ||
| 300 | + addBlurFields("#profile_data_personal_website", "site_error", invalid_site_validation); | ||
| 301 | + addBlurFields("#profile_data_organization_website", "site_error", invalid_site_validation); | ||
| 293 | }); | 302 | }); |
| 294 | })(); | 303 | })(); |
public/style.css
| @@ -118,3 +118,12 @@ | @@ -118,3 +118,12 @@ | ||
| 118 | border: solid 1px #000; | 118 | border: solid 1px #000; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | +#profile-data .invalid { | ||
| 122 | + border-color: rgb(127, 0, 0); | ||
| 123 | + box-shadow: 0px 0px 7px red; | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +#profile-data .validated { | ||
| 127 | + box-shadow: 0px 0px 7px green; | ||
| 128 | + border-color: rgb(0, 80, 0) | ||
| 129 | +} | ||
| 121 | \ No newline at end of file | 130 | \ No newline at end of file |