PageSourceSearch

https://account.globalrailwayreview.com/JavaScript/inform/validator.inline.class.js

js globalrailwayreview.com collected 2026-10-02 03:28:02 UTC 14,745 bytes, 476 lines download raw bytes

1/*
2---
3
4requires: [Form.Validator, Form.Validator.Inline, Element.data]
5
6provides: [Form.Validator.Inline.Extended]
7
8...
9*/
10
11(function($, window, document) {
12  Form.Validator.Inline.Extended = new Class({
13    Extends: Form.Validator.Inline,
14    options: {
15      scrollToErrorsOnSubmit: false,
16      evaluateFieldsOnBlur: false,
17      evaluateFieldsOnChange: false,
18      scrollDeduction: 50
19    },
20
21    initialize: function(form, options) {
22      this.parent(form, options);
23      var self = this;
24      form.getElements("button").addEvent("click", function(e) {
25        if (e.target.get("class").contains("novalidate")) {
26          self.stop();
27        }
28      });
29    },
30
31    showAdvice: function(className, field) {
32      var advice = this.getAdvice(className, field);
33      if (
34        advice &&
35        !field.retrieve("$moo:" + this.getPropName(className)) &&
36        (advice.getStyle("display") == "none" ||
37          advice.getStyle("visiblity") == "hidden" ||
38          advice.getStyle("opacity") == 0)
39      ) {
40        field.store("$moo:" + this.getPropName(className), true);
41        this.options.showError(advice);
42        this.fireEvent("showAdvice", [field, advice, className]);
43        // ADDITION
44        var fieldsets = field.getParent(".field").getParents("fieldset");
45
46        if (fieldsets.length >= 2) {
47          if (fieldsets[0].getParent(".field")) {
48            fieldsets[0].getParent(".field").addClass("fieldError");
49          } else {
50            fieldsets[0].addClass("fieldError");
51          }
52        } else {
53          field.getParent(".field").addClass("fieldError");
54        }
55        // END ADDITION
56      }
57    },
58
59    hideAdvice: function(className, field) {
60      var advice = this.getAdvice(className, field);
61      if (advice && field.retrieve("$moo:" + this.getPropName(className))) {
62        field.store("$moo:" + this.getPropName(className), false);
63        this.options.hideError(advice);
64        this.fireEvent("hideAdvice", [field, advice, className]);
65        // ADDITION
66        var errors = field
67          .getParent(".fieldError")
68          .getElements(".validation-advice");
69        var detectError = false;
70        errors.each(function(error) {
71          if (error.getStyle("display") === "block") {
72            detectError = true;
73          }
74        });
75        if (!detectError) {
76          var fieldsets = field.getParent(".field").getParents("fieldset");
77          if (fieldsets.length >= 2) {
78            if (fieldsets[0].getParent(".field")) {
79              fieldsets[0].getParent(".field").removeClass("fieldError");
80            } else {
81              fieldsets[0].removeClass("fieldError");
82            }
83          } else {
84            field.getParent(".field").removeClass("fieldError");
85          }
86        }
87        // END ADDITION
88      }
89    },
90
91    insertAdvice: function(advice, field) {
92      //Check for error position prop
93      var props = field.get("validatorProps");
94      //Build advice
95      if (!props.msgPos || !document.id(props.msgPos)) {
96        // ADDITION
97        var fieldsets = field.getParent(".field").getParents("fieldset");
98        if (fieldsets.length >= 2) {
99          if (fieldsets[0].getParent(".field")) {
100            fieldsets[0].getParent(".field").grab(advice, "top");
101          } else {
102            fieldsets[0].grab(advice, "top");
103          }
104        } else {
105          field.getParent(".field").grab(advice, "top");
106        }
107        // END ADDITION
108      } else {
109        document.id(props.msgPos).grab(advice);
110      }
111    },
112
113    // ADDITION
114      onSubmit: function (event) {
115      
116
117          let dpa = this.element.getElement(".dpaMandatory");
118          console.log(dpa)
119          if (dpa) {
120              let isValid = true;
121            
122              const inputs = this.element.getElement(".dpaMandatory input[type='radio'], .dpaMandatory input[type='checkbox']");
123              const errorBlock = this.element.getElement('.dpaMandatory .validation-advice')
124                  const oneChecked = Array.from(inputs).some(input => input.checked);
125
126                  if (!oneChecked) {
127                      isValid = false;
128                  }
129                  if (!isValid) {
130                      event.stop();
131                      dpa.classList.add('fieldError');
132                      errorBlock.style.display = "block";
133                  } else {
134                      dpa.classList.remove('fieldError');
135                      errorBlock.style.display = "none";
136                  }
137              
138          } 
139      if (!this.validate(event) && event) {
140        event.stop();
141        var self = this;
142          if (this.element.getElements(".fieldError").length > 0) {
143        
144          this.element
145            .getElements(".collapse")
146            .removeClass("collapsed")
147            .setStyle("height", "auto")
148            .addClass("collapseError");
149          this.element
150            .getElements(".fieldError")[0]
151            .getElements(".validation-advice")
152            .each(function(el) {
153              if (el.getStyle("display").contains("block")) {
154                $(window).scrollTo(
155                  0,
156                  el.getPosition().y - self.options.scrollDeduction
157                );
158                self.element.getElements(".validation-failed")[0].focus();
159              }
160            });
161          $$("body").removeClass("processing");
162        }
163      } else if (!event || event.event.cancelBubble !== true) {
164          console.log()
165        $(window).fireEvent("AD:FormComplete");
166        this.reset();
167      }
168    }
169    // END ADDITION
170  });
171
172  // Custom error messages
173  Locale.define("en-US", "FormValidator", {
174    reqChkByName: "Please select an {label}.",
175    integer: "Please only enter numbers."
176  });
177  Form.Validator.add("required", {
178    errorMsg: function() {
179      return Form.Validator.getMsg("required");
180    },
181    test: function(element) {
182      if (
183        element.type === "text" ||
184        (element.type === "textarea" && element.value.length > 0)
185      )
186        element.set("value", element.value.trim());
187      return !Form.Validator.getValidator("IsEmpty").test(element);
188    }
189  });
190
191  Form.Validator.add("validate-other", {
192    errorMsg: "You must specify other",
193    test: function(element) {
194      var $select = $(element).getPrevious("select"),
195        $checkbox = $(element).getPrevious('input[type="checkbox"]'),
196        $checkboxParent = $checkbox ? $checkbox.getParent("other") : null,
197        $radio = $(element).getPrevious('input[type="radio"]'),
198        $radioParent = $radio ? $radio.getParent("other") : null,
199        $prevElement = $select
200          ? $select
201          : $checkboxParent
202          ? $checkbox
203          : $radioParent
204          ? $radio
205          : null;
206
207      return (
208        !$prevElement ||
209        !$prevElement.get("value").contains("other") ||
210        $(element).get("value")
211      );
212    }
213  });
214
215  Form.Validator.add("validate-integer", {
216    errorMsg: Form.Validator.getMsg.pass("integer"),
217    test: function(element) {
218      return (
219        Form.Validator.getValidator("IsEmpty").test(element) ||
220        /^(-?[0-9]\d*|0)$/.test(element.get("value"))
221      );
222    }
223  });
224
225  Form.Validator.add("validate-reqchk-byname", {
226    errorMsg: function(element, props) {
227      return Form.Validator.getMsg("reqChkByName").substitute({
228        label: "option"
229      });
230    },
231    test: function(element, props) {
232      var grpName = props.groupName || element.get("name"),
233        oneCheckedItem = $$(document.getElementsByName(grpName)).some(function(
234          item,
235          index
236        ) {
237          return item.checked;
238        }),
239        fv = element.getParent("form").retrieve("validator");
240
241      if (oneCheckedItem && fv) fv.resetField(element);
242
243      return oneCheckedItem;
244    }
245  });
246
247  Form.Validator.add("validate-username-unique", {
248    errorMsg: function(element) {
249      if (
250        element.data("validatorProperties").PartyId !== undefined &&
251        element.data("validatorProperties").PartyId <= 0
252      ) {
253        return (
254          "This email address has already been registered. Have you " +
255          '<a href="ForgottenPassword"><strong>forgotten your password?</strong></a>'
256        );
257      } else {
258        return "This email address has already been registered.";
259      }
260    },
261    test: function(element) {
262      if (String.from(element.get("value")).trim().length == 0) return true;
263
264      var obj = JSON.parse(element.get("data-validator-properties")),
265        data = {
266          partyUid: obj.PartyId,
267          brandUid: obj.BrandId,
268          username: element.get("value"),
269          pageId: -1
270        },
271        isValid = false;
272
273      new Request({
274        url: "/AJAX/jsonPage.aspx?act=IsValidUsername",
275        method: "post",
276        data: data,
277        async: false,
278        onSuccess: function(response) {
279          var code = JSON.parse(response);
280          isValid = code.IsUsernameAvailable;
281        }
282      }).send();
283
284      return isValid;
285    }
286  });
287
288  Form.Validator.add("validate-current-password", {
289    errorMsg:
290      "The current password you have entered is incorrect. Please enter a different password.",
291    test: function(element) {
292      var currentPassword = String.from(element.get("value")),
293        newPassword;
294
295      try {
296        newPassword = String.from(
297          element
298            .getParent(".group")
299            .getElement(".validate-new-password")
300            .get("value")
301        );
302      } catch (e) {
303        return false;
304      }
305
306      if (currentPassword.length == 0 && newPassword.length == 0) return true;
307
308      var isValid = false,
309        properties = JSON.parse(element.get("data-validator-properties")),
310        data = {
311          partyUid: properties.PartyId,
312          brandUid: properties.BrandId,
313          currentpassword: currentPassword,
314          pageId: -1
315        };
316
317      new Request({
318        url: "/AJAX/jsonPage.aspx?act=ValidateCurrentPassword",
319        method: "post",
320        data: data,
321        async: false,
322        onSuccess: function(response) {
323          var code = JSON.parse(response);
324
325          isValid = code.IsValid;
326        }
327      }).send();
328
329      return isValid;
330    }
331  });
332
333  Form.Validator.add("validate-new-password", {
334    errorMsg:
335      "New password is required and it has to be at least 8 characters long.",
336    test: function(element) {
337      var currentPassword,
338        currentPasswordElement,
339        newPassword = String.from(element.get("value"));
340
341      try {
342        currentPasswordElement = element
343          .getParent(".field.group")
344          .getElement(".validate-current-password");
345        currentPassword = String.from(currentPasswordElement.get("value"));
346      } catch (e) {
347        return false;
348      }
349
350      if (newPassword.length == 0 && currentPassword.length == 0) return true;
351
352      return newPassword.trim().length >= 8;
353    }
354  });
355
356  Form.Validator.add("validate-vat-number", {
357    errorMsg:
358      "A valid VAT registration number must be supplied or leave blank.",
359    test: function(element) {
360      var self = this,
361        vatNumber = String.from(element.get("value"));
362
363      if (vatNumber.length == 0) return true;
364
365      var isValid = false,
366        data = {
367          SelectedId: element
368            .getParent("form")
369            .getElement("select[name=billingAddressSelect]")
370            ? element
371                .getParent("form")
372                .getElement("select[name=billingAddressSelect]")
373                .get("value")
374            : "",
375          VatNumber: vatNumber,
376          CountryId: element
377            .getParent("form")
378            .getElement("select[name=BillingCountry1]")
379            ? element
380                .getParent("form")
381                .getElement("select[name=BillingCountry1]")
382                .get("value")
383            : ""
384        };
385
386      new Request({
387        url: "/AJAX/jsonPage.aspx?act=validateVATNumber",
388        method: "post",
389        data: data,
390        async: false,
391        onSuccess: function(response) {
392          var code = JSON.parse(response);
393
394          isValid = code.IsValid;
395
396          if (isValid == false) {
397            self.errorMsg = code.Message;
398          }
399        }
400      }).send();
401
402      return isValid;
403    }
404    });
405
406    Form.Validator.add("validate-company", {
407        errorMsg: function (element) {
408            return "The entered organisation/company name is not found. Please contact us if you believe this to be incorrect.";            
409        },
410        test: function (element) {
411            if (String.from(element.get("value")).trim().length == 0) return true;
412            data = {
413              company: element.get("value")
414            };
415            var isValid = false;
416            new Request({
417                url: "/AJAX/jsonPage.aspx?act=IsValidCompany",
418                method: "post",
419                data: data,
420                async: false,
421                onSuccess: function (response) {
422                  var code = JSON.parse(response);
423                  isValid = code.CompanyFound;
424                }
425            }).send();
426
427            if ($('nomatchesfound')) {
428              $('nomatchesfound').destroy();
429            }
430
431            return isValid;
432        }
433    });
434
435  window.addEvent("domready", function() {
436    $$("DIV.informWrapper").each(function(element) {
437      new AbacusAD._preventDoubleClick();
438    });
439  });
440
441  AbacusAD._preventDoubleClick = new Class({
442    Implements: [Options],
443    options: {
444      buttons: ".field.buttons"
445    },
446    initialize: function(options) {
447      this.setOptions(options);
448      this.setupVars();
449      this.setupEvents();
450    },
451
452    setupVars: function() {
453      this.$body = $(document.body);
454      this.buttons = $$(this.options.buttons).getElements("button");
455    },
456
457    setupEvents: function() {
458      var self = this;
459      $(window).addEvent("AD:FormComplete", function() {
460        self.processing();
461        self.disableButtons();
462      });
463    },
464
465    processing: function() {
466      this.$body.addClass("processing");
467    },
468
469    disableButtons: function() {
470      var self = this;
471      this.buttons.each(function(button) {
472        button.addClass("disabled");
473      });
474    }
475  });
476})(document.id, window, document);

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.