PageSourceSearch

https://sec.carddass.com/jp/js/validator.js

js carddass.com collected 2026-10-02 03:26:48 UTC 2,618 bytes, 62 lines download raw bytes

1(function( factory ) {
2	if ( typeof define === "function" && define.amd ) {
3		define( ["jquery", "../jquery.validate"], factory );
4	} else if (typeof module === "object" && module.exports) {
5		module.exports = factory( require( "jquery" ) );
6	} else {
7		window.Validator = factory(jQuery);
8	}
9}(function( $ ) {
10
11	/**
12 * フォームのバリデーションを初期化し、サーバー側の結果を適用する
13 * @param {HTMLFormElement|jQuery} formEl 対象フォームのDOMまたはjQueryオブジェクト
14 * @param {Object} rules jQuery Validateのルール
15 * @param {Object} messages jQuery Validateのメッセージ
16 * @param {Object} serverResults サーバー側のバリデーション結果 (true/false)
17 */
18function initFormValidation(formEl, rules, messages, serverResults) {
19	const $form = $(formEl);
20
21	// jQuery Validateのデフォルト設定
22	$.validator.setDefaults({
23		errorClass: "custom-error",          // エラー時に追加するCSSクラス
24        errorElement: "p",                   // エラー表示のタグ
25        highlight: el => $(el).addClass("input-error"),   // エラー時にフォーム要素にクラス追加
26        unhighlight: el => $(el).removeClass("input-error"), // エラー解除時にクラス削除
27        errorPlacement: (error, el) => error.insertAfter(el) // エラー要素の挿入位置
28	});
29	// フォームにバリデーションを適用
30	const validator = $form.validate({ rules, messages });
31	// サーバー側のバリデーション結果をフォームに反映
32	applyServerValidation(validator, messages, serverResults);
33}
34
35/**
36 * サーバー側のバリデーション結果をフォームに適用する
37 * @param {Object} validator jQuery Validateのインスタンス
38 * @param {Object} messages 前端のメッセージ
39 * @param {Object} results サーバー側の結果 { fieldName: { ruleName: true/false } }
40 */
41function applyServerValidation(validator, messages, results) {
42	if (!results || Object.keys(results).length === 0) return;
43	const showErrors = {};
44
45	// サーバー結果を1つずつチェック
46	for (const field in results) {
47		for (const rule in results[field]) {
48			if (!results[field][rule]) {
49				// 指定のメッセージがあれば使用、なければデフォルト
50				const msg = messages[field]?.[rule] || '入力が正しくありません';
51				showErrors[field] = showErrors[field] ? showErrors[field] + "、" + msg : msg;
52			}
53		}
54	}
55	// jQuery Validateにエラーを表示させる
56	validator.showErrors(showErrors);
57}
58
59// API return
60return { initFormValidation, applyServerValidation };
61
62}));

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.