1var srpForms = {}; 2srpForms.configs = {}; 3 4/* Vérifications de la validité des champs */ 5srpForms.checkField = function ($field) { 6 var inError = true; 7 var errorMsg = ''; 8 // Récupération de la configuration 9 var fieldType = $field.data('fieldtype'); 10 var configs = $.grep(srpForms.configs, function (c) { return c.type == fieldType; }) 11 if (configs.length <= 0) { 12 SRP.ConsoleLog("La configuration " + fieldType + " n'a pas été trouvée"); 13 return true; 14 } 15 var config = configs[0]; 16 errorMsg = config.errorMsg; 17 // Check requierd 18 if (config.required) { 19 inError = false; 20 var inputType = $field.prop("type"); 21 if (inputType == "checkbox") // check box 22 { 23 inError = !$field.is(":checked"); 24 } else if ($field.find("input[type=radio]").length > 0) // radio button 25 { 26 inError = $field.find("input[type=radio]:checked").length == 0; 27 } else if (inputType == "select-one") { 28 inError = ($field.val() == "-1"); 29 } 30 else if ($field.find("input[type=file]").length > 0) // FileArea 31 { 32 inError = $field.find("input.no-empty[type=file]").length == 0; 33 } 34 else if (inputType == "file") // File 35 { 36 if ($field.parent().parent().find("input[type=file]").length > 1) // case of FileArea 37 { 38 inError = $field.parent().parent().find("input.no-empty[type=file]").length == 0; 39 } 40 else { 41 inError = $field[0].files.length == 0; 42 } 43 } 44 else // autre 45 { 46 inError = !$field.val(); 47 } 48 } 49 else 50 { 51 inError = false; 52 } 53 54 // Check regex 55 if (!inError && config.regex && config.regex.length > 0 && $field.val()) { 56 for (var i = 0; i < config.regex.length; i++) { 57 var regex = config.regex[i]; 58 var inverse = false; 59 if (config.regex[i].indexOf("not:") == 0) { 60 regex = config.regex[i].substring(4); 61 inverse = true; 62 } 63 64 var regObj = new RegExp(regex); 65 var isValid = (inverse ^ regObj.test($field.val())); 66 67 if (!isValid) { 68 inError = true; 69 errorMsg = config.regexMessage[i]; 70 break; 71 } 72 } 73 } 74 75 //check length 76 if (!inError && config.maxLength && config.maxLength > 0) 77 { 78 var inputType = $field.prop("type"); 79 if ($field.find("input[type=file]").length > 0) // FileArea 80 { 81 $field.find("input[type=file]").each(function (index) { 82 if (!inError && $(this)[0].files.length > 0) { 83 inError = $(this)[0].files[0].size > config.maxLength; 84 } 85 }); 86 } 87 else if (inputType == "file") // File 88 { 89 if ($field.parent().parent().find("input[type=file]").length > 1) // case of FileArea 90 { 91 $field.parent().parent().find("input[type=file]").each(function (index) { 92 if (!inError && $(this)[0].files.length > 0) { 93 inError = $(this)[0].files[0].size > config.maxLength; 94 } 95 }); 96 } 97 else { 98 if ($field[0].files.length > 0) 99 inError = $field[0].files[0].size > config.maxLength; 100 } 101 } 102 } 103 104 //check accepted value 105 if (!inError && config.acceptedValue && config.acceptedValue.length > 0) { 106 var inputType = $field.prop("type"); 107 if ($field.find("input[type=file]").length > 0) // FileArea 108 { 109 $field.find("input[type=file]").each(function (index) { 110 if (!inError && $(this)[0].files.length > 0) { 111 inError = config.acceptedValue.indexOf($(this)[0].files[0].type.split('/')[1]) == -1; 112 } 113 }); 114 } 115 else if (inputType == "file") // File 116 { 117 if ($field.parent().parent().find("input[type=file]").length > 1) // case of FileArea 118 { 119 $field.parent().parent().find("input[type=file]").each(function (index) { 120 if (!inError && $(this)[0].files.length > 0) { 121 inError = config.acceptedValue.indexOf($(this)[0].files[0].type.split('/')[1]) == -1; 122 } 123 }); 124 } 125 else { 126 if ($field[0].files.length > 0) 127 inError = config.acceptedValue.indexOf($field[0].files[0].type.split('/')[1]) == -1; 128 } 129 } 130 } 131 132 srpForms.displayError($field, inError, errorMsg); 133 return !inError; 134} 135 136srpForms.checkPassword = function ($field) { 137 var $container = $field.closest('.field-wrapper'); 138 // Récupération de la configuration 139 // Récupération de la configuration 140 var fieldType = $field.data('fieldtype'); 141 var configs = $.grep(srpForms.configs, function (c) { return c.type == fieldType; }) 142 if (configs.length <= 0) { 143 SRP.ConsoleLog("La configuration " + fieldType + " n'a pas été trouvée"); 144 return; 145 } 146 var config = configs[0]; 147 148 if (config.regex) { 149 for (var i = 0; i < config.regex.length; i++) { 150 var regex = config.regex[i]; 151 var inverse = false; 152 if (config.regex[i].indexOf("not:") == 0) { 153 regex = config.regex[i].substring(4); 154 inverse = true; 155 } 156 157 var regObj = new RegExp(regex); 158 var isValid = (inverse ^ regObj.test($field.val())); 159 160 if (i == 0) { // Taille min 161 if (isValid) { 162 $container.find('.js-condition-8').css('opacity', '1'); 163 $container.find('.js-condition-8').css('color', '#0b9c00'); 164 } else { 165 $container.find('.js-condition-8').css('opacity', '.4'); 166 $container.find('.js-condition-8').css('color', '#4c4c4c'); 167 } 168 } 169 else if (i == 1) { // Complexity 170 if (isValid) { 171 $container.find('.js-condition-chiffre').css('opacity', '1'); 172 $container.find('.js-condition-chiffre').css('color', '#0b9c00'); 173 } else { 174 $container.find('.js-condition-chiffre').css('opacity', '.4'); 175 $container.find('.js-condition-chiffre').css('color', '#4c4c4c'); 176 } 177 } 178 else if (i == 2) { // Caractères 179 if (isValid) { 180 $container.find('.js-condition-caractere').css('opacity', '1'); 181 $container.find('.js-condition-caractere').css('color', '#0b9c00'); 182 } else { 183 $container.find('.js-condition-caractere').css('opacity', '.4'); 184 $container.find('.js-condition-caractere').css('color', '#4c4c4c'); 185 } 186 } 187 } 188 } 189} 190 191srpForms.displayError = function ($field, inError, msg) { 192 var $fieldParent = $field.closest(".field-wrapper"); 193 var $fieldMsg = $fieldParent.find('.field__msg--error'); 194 var $fieldPictoValid = $fieldParent.find('.js-picto-valider'); 195 var $fieldPictoDelete = $fieldParent.find('.js-field-content-delet'); 196 if (inError) { 197 $fieldParent.addClass('field--error'); 198 if ($fieldMsg.data("haserrormsg")) { 199 if (msg && msg.length > 0) 200 { 201 $fieldMsg.html(msg); 202 } 203 $fieldMsg.slideDown(); 204 } 205 $fieldPictoValid.hide(); 206 $fieldPictoDelete.show(); 207 } 208 else { 209 $fieldParent.removeClass('field--error'); 210 if ($fieldMsg.data("haserrormsg")) { 211 $fieldMsg.slideUp(); 212 } 213 $fieldPictoValid.show(); 214 $fieldPictoDelete.hide(); 215 } 216} 217 218 219srpForms.displayLabel = function ($field, state) { 220 var $fieldParent = $field.closest(".field-wrapper"); 221 var $fieldLabel = $fieldParent.find('.field__label'); 222 switch (state) { 223 case "up": 224 $fieldLabel.addClass('field__label--focus'); 225 break; 226 case "down": 227 $fieldLabel.removeClass('field__label--focus'); 228 break; 229 } 230} 231 232srpForms.displayInstruction = function ($field, state) { 233 var $fieldParent = $field.closest(".field-wrapper"); 234 var fieldInstruction = $fieldParent.find('.field__msg--instru
234ction'); 235 if (fieldInstruction.length <= 0) return; 236 237 switch (state) { 238 case "on": 239 $fieldParent.addClass('field--info'); 240 fieldInstruction.slideDown(); 241 break; 242 case "off": 243 $fieldParent.removeClass('field--info'); 244 fieldInstruction.slideUp(); 245 break; 246 } 247} 248 249srpForms.bindKeyUp = function (e) { 250 var $this = $(this); 251 var keyUpEvent = $this.data("keyup"); 252 if (keyUpEvent && window[keyUpEvent] && typeof (window[keyUpEvent]) == "function") { 253 window[keyUpEvent]($this); 254 } else if (keyUpEvent && srpForms[keyUpEvent] && typeof (srpForms[keyUpEvent]) == "function") { 255 srpForms[keyUpEvent]($this); 256 } 257} 258 259srpForms.bindChange = function (e) { 260 var $this = $(this); 261 var keyUpEvent = $this.data("change"); 262 if (keyUpEvent && window[keyUpEvent] && typeof (window[keyUpEvent]) == "function") { 263 window[keyUpEvent]($this); 264 } else if (keyUpEvent && srpForms[keyUpEvent] && typeof (srpForms[keyUpEvent]) == "function") { 265 srpForms[keyUpEvent]($this); 266 } 267} 268 269srpForms.validContainer = function ($container) { 270 var validatableItems = $container.find("[data-fieldtype]"); 271 var res = true; 272 validatableItems.each(function (index, item) { 273 if (!srpForms.checkField($(item))) { 274 res = false; 275 } 276 }); 277 278 $("form").data("isvalid", res); 279 280 return res; 281} 282 283srpForms.getConfigField = function ($field) { 284 var fieldType = $field.data('fieldtype'); 285 var configs = $.grep(srpForms.configs, function (c) { return c.type == fieldType; }) 286 return configs 287} 288 289 290/* Binding des événements JS */ 291$(document).ready(function () { 292 293 /* binding des evenements */ 294 $('.js-champ-a').each(function () { 295 if ($(this).val() != "") { 296 srpForms.displayLabel($(this), "up"); 297 }; 298 }); 299 300 // Pour gérer le cas des autocomplete par navigateur, on force le up du placeholder au changement de texte 301 $('.js-champ-a').on("change", function () { 302 if ($(this).val() !== "") { 303 srpForms.displayLabel($(this), "up"); 304 } 305 }); 306 307 $('.js-champ-a').focus(function () { 308 var $this = $(this); 309 var $fieldParent = $this.closest(".field-wrapper"); 310 var $fieldValid = $fieldParent.find(".js-picto-valider"); 311 var $fieldDelete = $fieldParent.find(".js-field-content-delet"); 312 var $fieldPlaceholder = $fieldParent.find(".field__placeholder"); 313 314 srpForms.displayInstruction($this, "on"); 315 $fieldValid.hide(); 316 if ($this.val() == "") { 317 srpForms.displayLabel($(this), "up"); 318 $fieldPlaceholder.fadeIn(200); 319 } else { 320 $fieldDelete.show(); 321 } 322 }); 323 324 $('.js-champ-a').focusout(function () { 325 var $this = $(this); 326 var $fieldParent = $this.closest(".field-wrapper"); 327 var $fieldDelete = $fieldParent.find(".js-field-content-delet"); 328 var $fieldPlaceholder = $fieldParent.find(".field__placeholder"); 329 330 if ($this.val() == "" && $this.attr('type') != "date") { 331 srpForms.displayLabel($this, "down"); 332 $fieldPlaceholder.hide(); 333 } else { 334 srpForms.checkField($this); 335 } 336 337 srpForms.displayInstruction($this, "off"); 338 $fieldDelete.hide(); 339 }); 340 341 $('.js-champ-a').keyup(function () { 342 var $this = $(this); 343 var $fieldParent = $this.closest(".field-wrapper"); 344 var $fieldDelete = $fieldParent.find(".js-field-content-delet"); 345 var $fieldPlaceholder = $fieldParent.find(".field__placeholder"); 346 347 $fieldPlaceholder.hide(); 348 if ($this.val() != "") { 349 $fieldDelete.show(); 350 } else { 351 $fieldDelete.hide(); 352 $fieldPlaceholder.fadeIn(200); 353 } 354 }); 355 356 $('.js-champ-a[data-keyup]').keyup(srpForms.bindKeyUp); 357 $('.js-champ-a[data-keyup]').trigger("keyup");
358 $('input[data-change]').change(srpForms.bindChange); 359 $('input[data-change]').trigger("change"); 360 361 $('.js-field-content-delet').mousedown(function (e) { 362 var $this = $(this); 363 var $fieldParent = $this.closest(".field-wrapper"); 364 var $fieldValue = $fieldParent.find(".field__field"); 365 var $fieldPlaceholder = $fieldParent.find(".field__placeholder"); 366 367 e.preventDefault(); 368 $fieldValue.val(''); 369 $this.hide(); 370 $fieldPlaceholder.fadeIn(200); 371 }); 372 $('.js-field-content-delet[data-keyup]').keyup(srpForms.bindKeyUp); 373 374 $('.field__passwordtoggle').mousedown(function (e) { 375 var $this = $(this); 376 var $fieldParent = $this.closest(".field-wrapper"); 377 var $fieldValue = $fieldParent.find(".field__field"); 378 379 e.preventDefault(); 380 $this.toggleClass('icon-oeil'); 381 $this.toggleClass('icon-oeil_barre'); 382 if ($fieldValue.attr('type') == "password") { 383 $fieldValue.attr('type', 'text'); 384 } else { 385 $fieldValue.attr('type', 'password'); 386 } 387 }); 388 389 $("form").submit(function (e) { 390 var formIsValid = $("form").data("isvalid") === false ? false : true; 391 if (!formIsValid) { 392 // Validation globale et spécifique au formulaire 393 return srpHelper.stopEventPropagation(e); 394 } 395 }); 396});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.