PageSourceSearch

https://debtorcc.org/Content/js/parsleyValidations.js

js debtorcc.org collected 2026-09-26 04:51:30 UTC 13,022 bytes, 354 lines download raw bytes

1
2function onkeychange(id) {
3
4    var clas = $(id).attr('class');
5    var clas1 = $(id).val();
6
7    if (clas !== "form-control") {
8        $(id).parsley().validate();
9        clas = $(id).attr('class');
10        if ($(id).hasClass("parsley-error")) {
11            $(id).closest('div').addClass('input-error');
12
13            return false;
14
15        } else if ((clas1 == "" || clas1 == null) && clas != "form-control parsley-success" && clas != "form-control") {
16            $(id).closest('div').addClass('input-error');
17
18            const containsplaceholder = $(id).attr("placeholder");
19            if (typeof containsplaceholder !== 'undefined' && containsplaceholder !== false) {
20                $(id).attr("placeholder", placeholder);
21            }
22            return false;
23
24        } else {
25            $(id).closest('div').removeClass('input-error');
26            if (document.getElementById(id.id + "_Error")) { document.getElementById(id.id + "_Error").innerHTML = document.getElementById(id.id).getAttribute("placeholder"); }
27
28            return false;
29
30        }
31    }
32    else {
33        $(id).closest('div').removeClass('input-error');
34        return false;
35    }
36}
37
38// Restricts input for each element in the set of matched elements to the given inputFilter.
39(function ($) {
40    $.fn.inputFilter = function (inputFilter) {
41        return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function () {
42            if (inputFilter(this.value)) {
43                this.oldValue = this.value;
44                this.oldSelectionStart = this.selectionStart;
45                this.oldSelectionEnd = this.selectionEnd;
46            } else if (this.hasOwnProperty("oldValue")) {
47                this.value = this.oldValue;
48                this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
49            } else {
50                this.value = "";
51            }
52        });
53    };
54}(jQuery));
55
56function DropDownValidate(id) {
57    if ($('#' + id).attr('class') == "form-control parsley-error") {
58        $('#' + id).closest('div').addClass('input-error');
59        $('#' + id).closest('div').find('span.jcf-select-form-control').addClass("parsley-error");
60        $('#' + id).closest('div').find("span.jcf-option-hideme").addClass("selectparsleycolor");
61
62        return false;
63    }
64    else if ($('#' + id).attr('class') == "form-control jcf-hidden parsley-success") {
65        $('#' + id).closest('div').removeClass('input-error');
66        $('#' + id).closest('div').find('span.jcf-select-form-control').removeClass("parsley-error");
67        $('#' + id).find("span.jcf-option-hideme").removeClass("selectparsleycolor");
68    }
69}
70
71$(document).ready(function () {
72    // bind Parsley to the form
73    // excluded: "input[type=button], input[type=submit], input[type=reset], input[type=hidden], [disabled], :hidden" 
74    $("form").parsley({ excluded: "input[type=button], input[type=submit], input[type=reset], input[type=hidden], [disabled], :not(select):hidden", focus: "none" });
75
76    $("input[data-type='digits']").inputFilter(function (value) { return /^-?\d*$/.test(value); });
77    $("input[data-type='number']").inputFilter(function (value) { return /^-?\d*[.,]?\d*$/.test(value); });
78
79    // $("input[data-type='text']").inputFilter(function(value) { return /[^\W]*$/.test(value); });
80
81    // Whenever parsley validates successfully, we enable the submit button
82    window.Parsley.on('form:success', function () {
83        this.$element.find('.button--submit').prop('disabled', false).trigger('removeTooltip');
84    });
85
86    // Add custom validation for selects
87    window.Parsley.addValidator("notEqual", {
88        validateString: function (val, elem) {
89
90            return val !== $(elem).val();
91        }
92    });
93
94    // When a validation error occurs, we disable the submit button
95    //window.Parsley.on('form:error', function() {
96    //    this.$element.find('.button--submit').prop('disabled', true).trigger('addTooltip');
97    //});
98
99    // Disable the validation for hidden elements
100    $.listen('parsley:field:validated', function (fieldInstance) {
101        if (fieldInstance.$element.is(":hidden") && fieldInstance.$element[0].tagName !== 'SELECT') {
102            // hide the message wrapper
103            fieldInstance._ui.$errorsWrapper.css('display', 'none');
104
105            // set validation result to true
106            fieldInstance.validationResult = true;
107            return true;
108        }
109    });
110
111    // We need to monitor all form fields and force Parsley's validation manually
112    // This will result in enabling or disabling the submit button
113    //$("form :input").on('click focus keyup touch change', function() {
114    //    const selectedInput = $(this);
115    //    selectedInput.closest('form').parsley().validate();
116
117    //    if ($(this).closest('form').parsley().isValid()) {
118    //        $('#submit').prop('disabled', false);  
119    //    } else {
120    //        $('#submit').prop('disabled', 'disabled');
121    //    }
122    //});
123
124    $("form :input[type!='button']").on('blur', function () {
125
126        const selectedInput = $(this);
127        selectedInput.parsley().validate();
128        onkeychange(selectedInput);
129
130    });
131
132    $(".select--custom").on("focusout", function () {
133
134        const select = $(this).find('select');
135        const label = $(this).find('span.label');
136
137        $(select).parsley().validate();
138        if (select.hasClass('parsley-error')) {
139           // $(this).addClass('input-error');
140            $(label).css("color", "red");
141        }
142
143        if (select.hasClass('parsley-success')) {
144            $(this).removeClass('input-error');
145            $(label).css("color", "black");
146        }
147
148    });
149    //$(".select--custom").on("click focus keyup touch change", function () {
150    //    $(this).addClass('input-focus');
151    //    const select = $(this).find('select');
152    //    //const selectErrorWrapper = select.attr("data-parsley-errors-container");
153    //    // if (selectErrorWrapper) {
154    //    //     $(this).find(selectErrorWrapper).find(".parsley-errors-list.filled").addClass('d-block');
155    //    // }
156
157    //    if (select.hasClass('parsley-error')) {
158    //        $(this).addClass('input-error');
159
160    //    }
161
162    //    if (select.hasClass('parsley-success')) {
163    //        $(this).removeClass('input-error');
164    //    }
165    //});
166});
167
168$(document).ready(function () {
169    $('#cl').click(function (e) {
170        e.preventDefault();
171        hideMessage();
172    });
173
174    $("input").bind("mouseup", function (e) {
175
176
177        var input = $(this),
178            oldValue = input.val();
179
180        if (oldValue == "") return;
181
182        // When this event is fired after clicking on the clear button
183        // the value is not cleared yet. We have to wait for it.
184        setTimeout(function () {
185            var newValue = input.val();
186            if (newValue == "") {
187                var clas = input.attr('class');
188                var clas1 = input.val();
189                if (clas != "form-control") {
190                    if (input.hasClass("parsley-success")) {
191                        //Added because Not triggering to parsley-error after parsley-success when error occured.
192                        input.parsley().validate();
193                    }
194                    clas = input.attr('class');
195                    if ($(this).hasClass("parsley-error")) {
196                        $(input).closest('div').removeClass().addClass('form-group input-error input-focused');
197                        if (document.getElementById(input.id + "_Error")) { document.getElementById(input.id + "_Error").innerHTML = ""; }
198
199                        return false;
200                    }
201                    else if ((clas1 == "" || clas1 == null) && clas != "form-control parsley-success") {
202                        input.parsley().validate();
203                        $(input).closest('div').removeClass().addClass('form-group input-error input-focused');
204                        $(input).blur().focus();
205                        return false;
206                    }
207                    else {
208                        $(input).closest('div').removeClass().addClass('form-group input-focused');
209                        if (document.getElementById(input.id + "_Error")) {
210                            //document.getElementById(input.id + "_Error").innerHTML = document.getElementById(input.id).getAttribute("placeholder");
211                            $("#" + input.id + "_Error").html(document.getElementById(input.id).getAttribute("placeholder"));
212                        }
213
214                        return false;
215                    }
216                }
217                else {
218                    $(input).closest('div').removeClass().addClass('form-group input-focused');
219                    return false;
220                }
221            }
222        }, 1);
223    });
224});
225
226//Script to restrict <> and [] charaters from input 
227$(document).ready(function () {
228    $("input[type != 'password']").on('input', function () {
229        var input = $(this).val();
230        var restrictChars = /[<>\[\]]/gi;
231        var isSplChar = restrictChars.test(input);
232        if (isSplChar) {
233            $(this).val(input.replace(restrictChars, ''));
234        }
235    });
236})
237function ResetParsleyValiation(form) {
238    $(form).parsley().reset();
239    $(form).find('input').each(function () {
240        $(this).parent().removeClass("input-error");
241    });
242    $('.selectric-form-control').each(function () {
243        $(this).parent().removeClass("input-error");
244        var element = $(this).find(".selectric");
245        var span = $(element).find("span");
246        span.css("color", "black");
247    });
248}
249
250function ShowValidationErrors(form) {
251
252    if ($(form).parsley().validate() === false) {
253        $(form).find('input').each(function () {
254
255            onkeychange(this);
256        });
257
258        $(form).find('select').each(function () {
259
260            if ($(this).hasClass('parsley-error')) {
261                $(this).addClass('input-error');
262                $(this).closest('.select--custom').addClass('input-error');
263                // $('#select--custom').addClass('input-error');
264                //$(".selectric .label").css("color", "red");
265
266            }
267            if ($(this).hasClass('parsley-success')) {
268                $(this).removeClass('input-error');
269                $(this).closest('.select--custom').removeClass('input-error');
270
271                // $('#select--custom').removeClass('input-error');
272               // $(".selectric .label").css("color", "black");
273            }
274        });
275        $('.tooltip-wrapper').tooltip('show');
276    }
277
278}
279
280
281window.Parsley
282    .addValidator('phoneValidator', {
283        validateString: function (value) {
284
285            if (value === '') {
286                return true;
287            }
288            var data = value.replace(/ /g, '').replace(/_/g, '');
289            if (data.startsWith('(0')) {
290                return false;
291            }
292           
293            if (data.length == 13  ) {
294                return true;
295            } else {
296                return false;
297            }
298        }
299
300    });
301window.Parsley
302    .addValidator('decimalValidator', {
303        validateString: function (value) {
304
305            if (value.toString().indexOf('.') >= 0) {
306                if (value.toString().trim().length == 1) {
307                    return false;
308                }
309
310                else {
311                    var ValidCharsReg = /^\d*\.?(\d+)*$/;
312                    if (ValidCharsReg.test(value))
313                        return true;
314                    else
315                        return false;
316                }
317            }
318            else {
319                var ValidCharsReg = /^\d*\.?(\d+)*$/;
320                if (ValidCharsReg.test(value))
321                    return true;
322                else
323                    return false;
324            }
325        }
326    })
327
328window.parsley.addValidator('creditcardvalidation', {
329    validateString: function (value) {
330        var data = value.replace(/\s+/g, '');
331        if (data.length < 15 || data.length > 19) {
332            return false;
333        }
334        else {
335            return true;
336        }
337    }
338});
339
340//jQuery.validator.addMethod(
341//    "multiemail",
342//    function (value, element) {
343//        if (this.optional(element)) // return true on optional element 
344//            return true;
345//        var emails = value.split(/[;,]+/); // split element by , and ;
346//        valid = true;
347//        for (var i in emails) {
348//            value = emails[i];
349//            valid = valid && jQuery.validator.methods.email.call(this, $.trim(value), element);
350//        }
351//        return valid;
352//    },
353//    jQuery.validator.messages.email
354//);

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.