PageSourceSearch

https://kounokura.com/Js/ClientValidateScript.aspx

js kounokura.com collected 2026-10-02 18:53:36 UTC 9,859 bytes, 275 lines download raw bytes

1
2
3// クライアント検証
4function ClientValidate(cvalidator, e)
5{
6	// Replaces delimiter in phone number format if phone number has contain delimiter
7	replaceAHyphenInTelephone(cvalidator.controltovalidate, e);
8
9	var checked_message_html = "";
10	var languageLocaleId = getParamFromCss(cvalidator, 'languageLocaleId');
11	var countyIsoCode = getParamFromCss(cvalidator, 'countyIsoCode');
12
13	//alert($("#" + cvalidator.controltovalidate).attr('class'));
14
15	$.ajax({
16		url: "/Form/ValidateModule.aspx",
17		type: "post",
18		data: {
19			'group': cvalidator.validationGroup,
20			'control': document.getElementById(cvalidator.controltovalidate).name,
21			'value': e.Value,
22			'languageLocaleId' : languageLocaleId,
23			'countyIsoCode' : countyIsoCode
24		},
25		async: false,
26		success: function(data)
27		{
28			exec_submit_flg = 0;	// 二重押しチェック用
29			
30			checked_message_html = data.replace('<?xml version="1.0" encoding="utf-8" ?>', '').replace("@@ 1 @@", ": " + e.Value);
31			if (checked_message_html.length != 0)
32			{
33				e.IsValid = false;
34				
35				document.getElementById(cvalidator.id).innerHTML = checked_message_html;
36				
37				if (document.getElementById(cvalidator.controltovalidate).className.match(/ error_input /i) == null)
38				{
39					document.getElementById(cvalidator.controltovalidate).className += " error_input ";
40				}
41
42				// iosのSafariのfocus()の代用処理
43				var isIosSafari =
44					((navigator.userAgent.toLowerCase().indexOf("iphone") > -1)
45					|| (navigator.userAgent.toLowerCase().indexOf("ipad") > -1))
46					&& (navigator.userAgent.toLowerCase().indexOf("safari") > -1);
47				if (isIosSafari && (cvalidator.focusOnError == 't')){
48					var controllOffset = window.pageYOffset + document.getElementById(cvalidator.id).getBoundingClientRect().top;
49					if(window.pageYOffset > controllOffset)
50					{
51						document.getElementById(cvalidator.id).scrollIntoView();
52					}
53				}
54
55				resetErrorMessage(cvalidator);
56			}
57			else
58			{
59				e.IsValid = true;
60
61				document.getElementById(cvalidator.id).innerHTML = "";
62				
63				document.getElementById(cvalidator.controltovalidate).className =
64					document.getElementById(cvalidator.controltovalidate).className.replace(" error_input ", "");
65			}
66		},
67		error: function(data)
68		{
69			e.IsValid = false;
70			
71			checked_message_html = "システムエラーが発生しました";			
72			document.getElementById(cvalidator.id).innerHTML = checked_message_html;
73		}
74	});
75
76	function getParamFromCss(cvalidator, header)
77	{
78		if ($("#" + cvalidator.controltovalidate).attr('class'))
79		{
80			var myregex = new RegExp(" " + header + ":.+? ");
81			var match = $("#" + cvalidator.controltovalidate).attr('class').match(myregex);
82			if (match) return match[0].replace(header + ":", "").trim();
83		}
84		return "";
85	}
86
87	// Replaces delimiter in phone number format if phone number has contain delimiter
88	function replaceAHyphenInTelephone(id, e) {
89		$(".shortTel").each(function (index, element) {
90			var tel = $(".shortTel")[index].value;
91			if ((tel != undefined) && (tel != "")) {
92				if ((tel.split("-").length <= 2) && (id == element.id)) {
93					var value = e.Value.replace("-", "");
94					$("#" + element.id).val(value);
95					e.Value = value;
96				}
97				if ((tel.split("ï½°").length <= 2) && (id == element.id)) {
98					var value = e.Value.replace("ï½°", "");
99					$("#" + element.id).val(value);
100					e.Value = value;
101				}
102			}
103		});
104	}
105
106	// Reset the error message
107	function resetErrorMessage(customValidator) {
108		if (customValidator.id.toLowerCase().indexOf("zip") > -1) {
109			if (customValidator.classList.length >= 2) {
110				switch (customValidator.classList[1]) {
111					case "zip_input_error_message":
112						hideErrorMessage(cvalidator.className, 'shortZipInputErrorMessage');
113						break;
114
115					case "cvOwnerZipShortInput":
116						hideErrorMessage(cvalidator.className, 'sOwnerZipError');
117						break;
118
119					case "cvShippingZipShortInput":
120						hideErrorMessage(cvalidator.className, 'sShippingZipError');
121						break;
122
123					case "cvSenderZipShortInput":
124						hideErrorMessage(cvalidator.className, 'sSenderZipError');
125						break;
126
127					case "cvShippingZipShortInput":
128						hideErrorMessage(cvalidator.className, 'sShippingZipError');
129				}
130			}
131		}
132	}
133
134	// Hide unnecessary error messages
135	function hideErrorMessage(classNameCustomValidate, classNameZip) {
136		var zipErrorMessage = document.getElementsByClassName(classNameCustomValidate);
137		if (zipErrorMessage[0].innerHTML !== "")
138		{
139			if (document.getElementsByClassName(classNameZip)[0].innerHTML !== "")
140			document.getElementsByClassName(classNameZip)[0].innerHTML = "";
141		}
142	}
143}
144
145// Bind remove custom validator error on input change value
146function bindRemoveCustomValidateErrorOnInputChangeValue(controls) {
147	if ((controls === undefined) || (typeof controls !== "object")) return;
148
149	for (var i = 0; i < controls.length; i++) {
150		// Get input control and custom validate control ids (separated by one space)
151		var controlInfos = controls[i].split(' ');
152		if ((controlInfos.length !== 2) || (controlInfos[0] === '')) continue;
153
154		var inputControl = $('#' + controlInfos[0]);
155		var errorClass = 'error_input';
156		if (inputControl.length) {
157			// Remove class custom error from input control (when the page is post back event)
158			if ($(inputControl).hasClass(errorClass)) {
159				$(inputControl).removeClass(errorClass)
160			}
161
162			// Set attribute custom validate id (use for finding and removing error message)
163			$(inputControl).data('custom-validator-control-id', controlInfos[1]);
164			$(inputControl).bind('change', function () {
165				// Remove class custom error from input control (when the input change value)
166				if ($(inputControl).hasClass(errorClass)) {
167					$(inputControl).removeClass(errorClass)
168				}
169
170				// Remove display error text
171				if ($(this).data('custom-validator-control-id')) {
172					// Get custom validator ids (separated by plus(+))
173					var customValidatorIds = $(this).data('custom-validator-control-id').split('+');
174					for (var j = 0; j < customValidatorIds.length; j++) {
175						var customValidatorControl = $('#' + customValidatorIds[j]);
176						if (customValidatorControl.length) {
177							$(customValidatorControl).html('');
178						}
179					}
180				}
181			});
182		}
183	}
184}
185
186// Bind remove custom validate error when no error display
187function bindRemoveCustomValidateErrorWhenNoErrorDisplay(controls) {
188	if ((controls === undefined) || (typeof controls !== "object")) return;
189
190	for (var i = 0; i < controls.length; i++) {
191		// Get input control and custom validate control ids (separated by one space)
192		var controlInfos = controls[i].split(' ');
193		if ((controlInfos.length !== 2) || (controlInfos[0] === '')) continue;
194
195		var inputControl = $('#' + controlInfos[0]);
196		var errorClass = 'error_input';
197		if (inputControl.length) {
198
199			// Set attribute custom validate id (use for finding and removing error message)
200			$(inputControl).data('custom-validator-control-id', controlInfos[1]);
201
202			// Remove display error text
203			if ($(inputControl).data('custom-validator-control-id')) {
204				// Get custom validator ids (separated by plus(+))
205				var customValidatorIds = $(inputControl).data('custom-validator-control-id').split('+');
206				for (var j = 0; j < customValidatorIds.length; j++) {
207					var customValidatorControl = $('#' + customValidatorIds[j]);
208					if ($(customValidatorControl).css("visibility") === 'hidden') {
209						// Remove error message
210						$(customValidatorControl).empty();
211						// Remove class custom error from input control
212						if ($(inputControl).hasClass(errorClass)) {
213							$(inputControl).removeClass(errorClass)
214						}
215					} else if (($(customValidatorControl).length == 0)
216						&& ($(inputControl).prev().is("select")
217						&& ($(inputControl).val() !== ''))) {
218
219						// Remove class custom error from input control when the drop down list control has value and no error display
220						// Sush as: ddlOwnerBirthDay, ...
221						if ($(inputControl).hasClass(errorClass)) {
222							$(inputControl).removeClass(errorClass)
223						}
224					}
225				}
226			}
227		}
228	}
229}
230
231var validators = {};
232// Client validate for order shipping select page
233function ClientValidateForOrderShippingSelectPage(cvalidator, e) {
234	ClientValidate(cvalidator, e);
235	let hiddenIndex = $(cvalidator.closest('.orderBoxLarge')).find('.hiddenIndex');
236	let cartBox = $(cvalidator.closest('.cartBox')).find('.invalidInputError');
237	let control = cvalidator.id + '|' + hiddenIndex[0].innerHTML;
238	let isGift = hiddenIndex[0].getAttribute("gift") == "True";
239
240	if (isGift == false) {
241		cartBox.css("display", "none");
242		return
243	}
244	let cartBoxId = cartBox[0].id;
245	if (validators[cartBoxId] == undefined) {
246		validators[cartBoxId] = [];
247	}
248	if (e.IsValid == false) {
249		validators[cartBoxId].push(control);
250	} else {
251		validators[cartBoxId] = validators[cartBoxId]
252			.filter((value) => value !== control);
253	}
254	if (validators[cartBoxId].length > 0) {
255		cartBox[0].innerHTML = getValidatorErrorMessage(cartBoxId);
256		cartBox[0].scrollIntoView({ behavior: 'smooth', block: 'center' });
257	} else {
258		cartBox[0].innerHTML = '';
259	}
260}
261
262// Get validator error message
263function getValidatorErrorMessage(cartBoxId) {
264	let groupValidatorsForCheck = validators[cartBoxId];
265	let subErrorMessages = [];
266	groupValidatorsForCheck.forEach((value) => {
267		let splitedControls = value.split('|');
268		let subErrorMessage = '配送先' + splitedControls[1] + 'で入力に不備があります';
269		if (subErrorMessages.includes(subErrorMessage) == false) {
270			subErrorMessages.push(subErrorMessage);
271		}
272	});
273	let errorMessage = subErrorMessages.sort().join('<br />');
274	return errorMessage;
275}

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.