PageSourceSearch

https://careers.newcops.govt.nz/shared-assets/validation/validation_custom.js

js newcops.govt.nz collected 2026-10-02 20:27:40 UTC 14,203 bytes, 338 lines download raw bytes

1/*
2 * Inline Form Validation Customisations
3 *
4 * Copyright(c) 2012, Springboard
5 *
6 * Version - 1.0 
7 * Author - Nirmal Sivaram
8 * Last modified - 10/08/2012
9 * 
10 * DO NOT MODIFY ANYTHING IN THIS FILE WITHOUT CONSULTING NIRMAL
11 */
12
13
14/*************************************************************
15Based on the buttons in the page decide which form to validate
16**************************************************************/
17jQuery(document).ready(function () {
18	// Lets decide which form we are validating for
19	if (jQuery("input[name='in_create_account']").length > 0) {
20		validateRegistration();
21	}
22	if (jQuery("input[name='in_save_ac_button']").length > 0) {
23		validateUpdatedetails();
24	}
25	if (jQuery("input[name='in_edit']").length > 0) {
26		validateProfile();
27	}
28	if (jQuery('input[value="Send Password"]').length > 0) {
29		validateSendPassword();
30	}
31	if (jQuery("input[name='in_submit_app']").length > 0) {
32		validateAppform();
33	}
34	if (jQuery("input[value='Next']").length > 0) {
35		validateAppform();
36	}
37	if (jQuery("input[name='in_sendbut']").length > 0) {
38		validateEmailafriend();
39	}
40
41	// SLI Add Word Count Limit validation to a custom column. First attribute is to select the field, second attribute is to select the word count label.
42	//wordCountLimit('#in_values_18207','#count-label-extracurricular');
43
44	//YA: WCAG - assign aria-required attribute to all mandatory fields
45	$('[class*="validate[required"]').attr('aria-required', 'true');
46
47});
48
49/*************************************************************
50Start Registration form validation
51**************************************************************/
52function validateRegistration() {
53	//lets give the form an id and remove legacy onsubmit events
54	jQuery("main form[name='userdetails']").attr("id", "userdetails");
55	jQuery("form[id='userdetails']").removeAttr('onsubmit');
56	jQuery("input[name='in_create_account']").removeAttr('onclick');
57
58	// All fields in this form are basetags, so lets add validation dynamically
59	jQuery("input[name='in_fname']").addClass("validate[required]");
60	jQuery("input[name='in_lname']").addClass("validate[required]");
61	jQuery("input[name='in_username']").addClass("validate[required,custom[email]]");
62	jQuery("input[name='in_pwd']").addClass("validate[required]");
63
64	// SLI Validate checkbox privacy declaration
65	jQuery("input[name='in_privacy']").addClass("validate[required]");
66
67	//Lets add dynamic id to email & password fields so that we can check confirm email & password
68	jQuery("#userdetails input[name='in_username']").attr("id", "in_username_1");
69	jQuery("#userdetails input[name='in_pwd']").attr("id", "in_pwd_1");
70	jQuery("input[name='in_check_pwd']").addClass("validate[required,equals[in_pwd_1]]");
71
72
73	jQuery("input[name='in_email']:not(#tempReg input[name='in_email'])").addClass("validate[required,custom[email],equals[in_username_1]]");
74
75	// Temporary registration email field validation
76	//	jQuery("#tempReg input[name='in_email']").addClass("validate[required,custom[email]]");
77
78	//YA Assign 'for' attribute based on 'id' attribute
79	$('input[type!="hidden"], select, textarea').each(function () {
80		if (!$(this).attr('id')) {
81			$(this).attr('id', $(this).attr('name'));
82		}
83		$(this).closest('.form-group').find('label').attr('for', $(this).attr('id'));
84	});
85	// binds form submission and fields to the validation engine for the final submit
86	jQuery("input[name='in_create_account']").click(function () {
87		jQuery("form[id='userdetails']").validationEngine();
88	});
89}
90
91
92/*************************************************************
93Start Update Details form validation
94**************************************************************/
95function validateUpdatedetails() {
96	//lets give the form an id and remove legacy onsubmit events
97	jQuery("form[name='userdetails']").attr("id", "userdetails");
98	jQuery("form[id='userdetails']").removeAttr('onsubmit');
99
100	// All fields in this form are basetags, so lets add validation dynamically
101	jQuery("input[name='in_fname']").addClass("validate[required]");
102	jQuery("input[name='in_lname']").addClass("validate[required]");
103	jQuery("input[name='in_username']").addClass("validate[required,custom[email]]");
104	jQuery("input[name='in_old_pwd']").addClass("validate[required]");
105
106	//Lets add dynamic id to email field so that we can check confirm email
107	jQuery("input[name='in_username']").attr("id", "in_username");
108
109	jQuery("input[name='in_email']").addClass("validate[required,custom[email],equals[in_username]]");
110
111
112	//YA: Assign 'for' attribute based on 'id' attribute
113	$('input[type!="hidden"], select, textarea').each(function () {
114		if (!$(this).attr('id')) {
115			$(this).attr('id', $(this).attr('name'));
116		}
117		$(this).closest('.form-group').find('label').attr('for', $(this).attr('id'));
118	});
119	// binds form submission and fields to the validation engine for the final submit
120	jQuery("input[name='in_save_ac_button']").click(function () {
121		jQuery("form[id='userdetails']").validationEngine();
122	});
123
124}
125
126/*************************************************************
127Start Email a Friend form validation
128**************************************************************/
129function validateEmailafriend() {
130	//lets give the form an id 
131	jQuery('input[name="in_sendbut"]').closest("form").attr("id", "emailFriend");
132
133	// All fields in this form are basetags, so lets add validation dynamically
134	jQuery("input[name='in_rcpt']").addClass("validate[required]");
135	jQuery("input[name='in_rcptemail']").addClass("validate[required,custom[email]]");
136	jQuery("input[name='in_from']").addClass("validate[required]");
137	jQuery("input[name='in_fromemail']").addClass("validate[required,custom[email]]");
138	jQuery("textarea[name='in_message']").addClass("validate[required]");
139
140	// binds form submission and fields to the validation engine for the final submit
141	jQuery("input[name='in_sendbut']").click(function () {
142		jQuery("form[id='emailFriend']").validationEngine();
143	});
144	//YA Assign 'for' attribute based on 'id' attribute
145	$('input[type!="hidden"], select, textarea').each(function () {
146		if (!$(this).attr('id')) {
147			$(this).attr('id', $(this).attr('name'));
148		}
149		$(this).closest('.form-group').find('label').attr('for', $(this).attr('id'));
150	});
151
152}
153
154/*************************************************************
155Start Profile form validation
156**************************************************************/
157function validateProfile() {
158	//lets give the form an id and remove legacy onsubmit events
159	jQuery("form[name='availform']").attr("id", "availform");
160	jQuery("form[id='availform']").removeAttr('onsubmit');
161	jQuery("input[name='in_edit']").removeAttr('onClick');
162
163	//We have the tagname's as the id, so lets remove them and create dynamic unique id's
164	jQuery('input[type!=hidden][id*="<"],select[id*="<"],textarea[id*="<"]').each(function (index) {
165		jQuery(this).removeAttr('id');
166		jQuery(this).uid();
167	});
168
169	//YA Assign 'for' attribute based on 'id' attribute
170	$('input[type!="hidden"], select, textarea').each(function () {
171		if (!$(this).attr('id')) {
172			$(this).attr('id', $(this).attr('name'));
173		}
174		$(this).closest('.form-group').find('label').attr('for', $(this).attr('id'));
175	});
176	
177	
178	// For basetags, lets add validation dynamically
179	jQuery("input[name='in_dphone']").addClass("validate[required,custom[integer]]");
180	//jQuery("input[name='in_mphone']").addClass("validate[groupRequired[contactphone],custom[integer]]");
181	jQuery("input[name='in_city']").addClass("validate[required]");
182	jQuery("input[name='in_state']").addClass("validate[required]");
183	jQuery("select#in_values_6100").addClass("validate[required]");
184	jQuery("select[name='in_fromcalc']").addClass("validate[required]");
185	jQuery('.mandatory').siblings('input[type="TEXT"]').addClass("validate[required]");
186
187	//Lets add validation for attachments
188	jQuery("#attachFiles :input[type='button']:first").addClass("validate[funcCall[checkAttachments]]");
189
190	//Lets add validation for the checkboxes for area of work
191	jQuery("#rasp_areaofwork input[type='CHECKBOX']").each(function (index) {
192		jQuery(this).addClass("validate[minCheckbox[2]]");
193	});
194
195	// binds form submission and fields to the validation engine for the final submit
196	jQuery("input[name='in_edit']").click(function () {
197		jQuery("form[id='availform']").validationEngine();
198	});
199
200}
201
202/*************************************************************
203Start Application form validation
204**************************************************************/
205function validateAppform() {
206	//lets remove legacy onsubmit events
207	jQuery("form[id='appform']").removeAttr('onsubmit');
208
209	//Lets remove them and create dynamic unique id's
210	jQuery('input[type!=hidden],select,textarea').each(function (index) {
211		jQuery(this).uid();
212	});
213
214	//YA Assign 'for' attribute based on 'id' attribute
215	$('input[type!="hidden"], select, textarea').each(function () {
216		if (!$(this).attr('id')) {
217			$(this).attr('id', $(this).attr('name'));
218		}
219		$(this).closest('.form-group').find('label').attr('for', $(this).attr('id'));
220	});
221
222	//Lets give the next, apply and multipage buttons all the same id
223	jQuery("input[value='Next']").attr("id", "apply");
224	jQuery("input[name='in_submit_app']").attr("id", "apply");
225	jQuery("input[name='in_multi_page']").attr("id", "apply");
226
227	jQuery("input[value='Save']").attr("id", "save");
228	jQuery("input[value='previous']").attr("id", "previous");
229	jQuery("input[value='Cancel']").attr("id", "cancel");
230
231	jQuery("input[value='Next']").removeAttr('onClick');
232
233	// For basetags, lets add validation dynamically
234	jQuery("input[name='in_first_name']").addClass("validate[required]");
235	jQuery("input[name='in_last_name']").addClass("validate[required]");
236	jQuery("input[name='in_contact_addr1']").addClass("validate[required]");
237	jQuery("input[name='in_contact_addr3']").addClass("validate[required]");
238	jQuery("select[name='in_aus_state']").addClass("validate[required]");
239	jQuery("input[name='in_contact_addr5']").addClass("validate[required]");
240	jQuery("input[name='in_email']").addClass("validate[required,custom[email]]");
241	// jQuery("input[name='in_phone']").addClass("validate[groupRequired[opt-phone],custom[integer]]");
242	// jQuery("input[name='in_work_phone']").addClass("validate[groupRequired[opt-phone],custom[integer]]");
243	jQuery("input[name='in_mobile_phone']").addClass("validate[required,custom[integer]]");
244
245
246	// SLI Add Word Count validation to a custom column
247	//jQuery("textarea[id='in_values_18207']").addClass("validate[custom[maxSize[150]]]");
248
249	//Lets add validation for attachments
250	jQuery("#attachFiles #attach-btn :input[type='button']:first").addClass("validate[funcCall[checkAttachments]]");
251	// YA add aria-describedby to attachments for WCAG
252	jQuery("#attachFiles #attach-btn :input[type='button']:first").attr('aria-describedby','attachments-notes');
253
254
255  $('.mandatory-js').find('input[type!=hidden], select, textarea').addClass('validate[required]');
256  $('.mandatory-email-js').find('input[type!=hidden]').addClass('validate[required,custom[email]]');
257  $('.mandatory-phone-js').find('input[type!=hidden]').addClass('validate[required,custom[integer]]');
258  $('.nonmandatory-js').find('input[type!=hidden], select, textarea').removeClass('validate[required]');
259
260	//Add validation for password fields at bottom of app form
261	/*
262	jQuery(".appFormPassword input#in_pwd").addClass("validate[required]");
263	jQuery(".appFormPassword input#in_check_pwd").addClass("validate[required,equals[in_pwd]]");
264	*/
265
266
267	jQuery("input#previous").click(function () {
268		jQuery("form[id='appform']").validationEngine('detach');
269	});
270
271	jQuery("input#save").click(function () {
272		jQuery("form[id='appform']").validationEngine('detach');
273	});
274
275	jQuery("input#cancel").click(function () {
276		jQuery("form[id='appform']").validationEngine('detach');
277	});
278
279	// binds form submission and fields to the validation engine for the final submit
280	jQuery("input[id='apply']").click(function () {
281		//below is needed for questionaires
282		jQuery("input[name='in_app_valid']").val('YES');
283		jQuery("form[id='appform']").validationEngine();
284	});
285}
286
287/*************************************************************
288Start send password form validation
289**************************************************************/
290function validateSendPassword() {
291	//lets give the form an id 
292	jQuery('input[value="Send Password"]').closest("form").attr("id", "sendPasswordForm");
293	jQuery('input[value="Send Password"]').removeAttr('onclick');
294	jQuery("form[id='sendPasswordForm']").removeAttr('onsubmit');
295	// All fields in this form are basetags, so lets add validation dynamically
296	jQuery("#in_username_sp").addClass("validate[required,custom[email]]");
297
298	// binds form submission and fields to the validation engine for the final submit
299	jQuery('input[value="Send Password"]').click(function () {
300		jQuery("form[id='sendPasswordForm']").validationEngine();
301	});
302
303	//YA Assign 'for' attribute based on 'id' attribute
304	$('input[type!="hidden"], select, textarea').each(function () {
305		if (!$(this).attr('id')) {
306			$(this).attr('id', $(this).attr('name'));
307		}
308		$(this).closest('.form-group').find('label').attr('for', $(this).attr('id'));
309	});
310}
311
312/*************************************************************
313Add custom word count validation and limit text length
314**************************************************************/
315function wordCountLimit(id, label) {
316
317	if (jQuery(id)) {
318		var limitWord = 150;
319		jQuery(id).keyup(function () {
320			$this = jQuery(this);
321			var regex = /\s+/gi;
322			var wordcount = jQuery.trim($this.val()).replace(regex, ' ').split(' ').length;
323			if (wordcount <= limitWord) {
324				chars = $this.val().length;
325			} else {
326				var text = jQuery(this).val();
327				var new_text = text.substr(0, chars);
328				jQuery(this).val(new_text);
329				wordcount--;
330			}
331			if (jQuery(id).val() == '') {
332				wordcount = 0;
333			}
334			jQuery(label).html(wordcount);
335		});
336		jQuery(id).keyup();
337	}
338}

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.