PageSourceSearch

https://riviera.jp/wp-content/themes/riviera/asset/js/form.js

js riviera.jp collected 2026-10-04 16:04:59 UTC 8,122 bytes, 232 lines download raw bytes

1// form.js
2// -- 通常
3$(function(){
4	// -- カットサンプル
5	// 削除ボタンをクリックでサンプル削除
6	// $( '.cutSmploptionBox_item tbody td a' ).on( 'click', function() {
7	// 	var $item = $( this ).parent().parent().parent();
8	// 	$item.remove();
9
10	// 	// サンプルがない場合
11	// 	if( !$( '.cutSmploptionBox_item tbody tr' ).length ){
12	// 		$( '.cutSmploptionBox_item' ).remove();
13	// 		$( '.cutSmploptionBox_txt' ).show();
14	// 		$( '.cutSmploptionBox_btn a' ).text( 'サンプルを選択する' );
15	// 	}
16	// 	return false;
17	// });
18	// サンプルがない場合
19	if( !$( '.cutSmploptionBox_item tbody tr' ).length ){
20		$( '.cutSmploptionBox_item' ).remove();
21		$( '.cutSmploptionBox_txt' ).show();
22		$( '.cutSmploptionBox_btn a' ).text( 'サンプルを選択する' );
23	}
24
25	// -- セレクトボックス選択で要素を表示
26	// var $firstShowItem = $( '.firstShowItem select' );
27	// $firstShowItem.on( 'change' ,function() {
28	// 	if( $firstShowItem.children( 'option:selected' ).text() !== '' ) {
29	// 		$( '.nextShowItem' ).fadeIn( 600 );
30	// 		$( '.firstShowItem_txt' ).fadeOut( 600 );
31	// 	} else {
32	// 		$( '.nextShowItem' ).fadeOut( 600 );
33	// 		$( '.firstShowItem_txt' ).fadeIn( 600 );
34	// 	}
35	// });
36
37	// -- フォームエラーがある場合
38	//クラス
39	const error_class       = 'errors';
40
41	//エラーメッセージ
42	const required_message  = '必須項目が未入力です';
43	const mail_message      = '有効なメールアドレスを入力してください';
44	const mailagain_message = 'メールアドレスが一致しません';
45	const tel_message       = '半角数字で入力してください';
46	const checkbox_message  = '「個人情報の取扱い」の内容に同意の上、チェックを入れてください。';
47
48	//正規表現
49	const mail_check        = "^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$";
50	const tel_check         = "^[0-9]+$";
51
52	//バリデーションの関数を定義
53	function validate( attr , message , check ) {
54		if( attr.val() == "" ){
55			if( attr.parent().hasClass( error_class ) ) {
56				attr.parent().find( '.errorMsg' ).text( required_message );
57			} else {
58				attr.parent().addClass( error_class );
59				attr.parent().find( 'input:last-child , button:last-child' ).after( '<p class="errorMsg">' + required_message + '</p>' );
60			}
61		} else if (!attr.val().match(check)) {
62			if( attr.parent().hasClass( error_class ) ) {
63				attr.parent().find( '.errorMsg' ).text( message );
64			} else {
65				attr.parent().addClass( error_class );
66				attr.parent().find( 'input:last-child , button:last-child' ).after( '<p class="errorMsg">' + message + '</p>' );
67			}
68		} else {
69			attr.parent().removeClass(error_class);
70			attr.parent().find( '.errorMsg' ).remove();
71		}
72	}
73	// 半角数字の関数
74	function hankaku( $outer , $this ) {
75		if( $this.val() ){
76			if( !$this.val().match( tel_check ) ) {
77				if( $this.parent().hasClass( error_class ) ) {
78					$this.parent().find( '.errorMsg' ).text( tel_message );
79				} else {
80					$this.parent().addClass( error_class );
81					$this.parent().find( 'input:last-child , button:last-child' ).after( '<p class="errorMsg">' + tel_message + '</p>' );
82				}
83			} else {
84				$this.parent().removeClass(error_class);
85				$this.parent().find( '.errorMsg' ).remove();
86			}
87		} else {
88			if( $outer.hasClass( 'required' ) ) {
89				if( $this.parent().hasClass( error_class ) ) {
90					$this.parent().find( '.errorMsg' ).text( required_message );
91				} else {
92					$this.parent().addClass( error_class );
93					$this.parent().find( 'input:last-child , button:last-child' ).after( '<p class="errorMsg">' + required_message + '</p>' );
94				}
95			} else {
96				$this.parent().removeClass(error_class);
97				$this.parent().find( '.errorMsg' ).remove();
98			}
99		}
100	}
101
102	// submiされた時にチェック
103	$( '#form' ).submit( function() {
104		// 直下のinput[type="text"]
105		$( 'tr.required td > input[type="text"]:not(.noreq)' ).each( function() {
106			var $outer = $( this ).parent();
107			if( $( this ).val() ){
108				$outer.removeClass( error_class );
109				$outer.find( '.errorMsg' ).remove();
110			} else {
111				if( !$outer.hasClass( error_class ) ) {
112					$outer.addClass( error_class );
113					$outer.append( '<p class="errorMsg">' + required_message + '</p>' );
114				}
115			}
116		});
117
118		// 2カラムのinput[type="text"]
119		$( 'tr.required td > .inputTxtCrm2 input[type="text"]:not(.noreq)' ).each( function() {
120			var $outer = $( this ).parent();
121			if( $( this ).val() ){
122				$( this ).removeClass( 'errr' );
123				if( !$outer.find( '.errr' ).length ){
124					$outer.removeClass( error_class );
125					$outer.find( '.errorMsg' ).remove();
126				}
127			} else {
128				$( this ).addClass( 'errr' );
129				if( $outer.find( '.errr' ).length ){
130					if( !$outer.hasClass( error_class ) ) {
131						$outer.addClass( error_class );
132						$outer.append( '<p class="errorMsg">' + required_message + '</p>' );
133					}
134				}
135			}
136		});
137
138		// dl内のinput[type="text"]
139		$( 'tr.required td dd input[type="text"]:not(.noreq)' ).each( function() {
140			var $outer = $( this ).parent();
141			if( $( this ).val() ){
142				$outer.removeClass( error_class );
143				$outer.find( '.errorMsg' ).remove();
144			} else {
145				if( !$outer.hasClass( error_class ) ) {
146					$outer.addClass( error_class );
147					$outer.append( '<p class="errorMsg">' + required_message + '</p>' );
148				}
149			}
150		});
151
152		// select
153		$( 'tr.required select' ).each( function() {
154			var $outer = $( this ).parent().parent();
155			if( $( this ).val() ){
156				$outer.removeClass( error_class );
157				$outer.find( '.errorMsg' ).remove();
158			} else {
159				if( !$outer.hasClass( error_class ) ) {
160					$outer.addClass( error_class );
161					$outer.append( '<p class="errorMsg">' + required_message + '</p>' );
162				}
163			}
164		});
165
166		// メール
167		validate( $( '#email' ) , mail_message , mail_check);
168
169		// メール再入力のチェック
170		var email_address = $( '#email' ).val(),
171			$email_again = $( '#email_again' ),
172			again_address = $email_again.val();
173
174		if( $email_again.val() == "" ){
175			if( $email_again.parent().hasClass( error_class ) ) {
176				$email_again.parent().find( '.errorMsg' ).text( required_message );
177			} else {
178				$email_again.parent().addClass( error_class );
179				$email_again.parent().find( 'input:last-child , button:last-child' ).after( '<p class="errorMsg">' + required_message + '</p>' );
180			}
181		} else if (  email_address == again_address  ) {
182			$email_again.parent().removeClass( error_class );
183			$email_again.parent().find( '.errorMsg' ).remove();
184		} else {
185			if( $email_again.parent().hasClass( error_class ) ) {
186				$email_again.parent().find( '.errorMsg' ).text( mailagain_message );
187			} else {
188				$email_again.parent().addClass( error_class );
189				$email_again.parent().find( 'input:last-child , button:last-child' ).after( '<p class="errorMsg">' + mailagain_message + '</p>' );
190			}
191		}
192
193		// 半角数字の場合
194		$( 'input.hankaku' ).each( function() {
195			if( $( this ).parent().hasClass( 'postCode' ) ){
196				var $outer = $( this ).parent().parent().parent();
197				hankaku( $outer , $( this ) );
198
199			} else {
200				var $outer = $( this ).parent().parent();
201				hankaku( $outer , $( this ) );
202			}
203		});
204
205 
206		// チェックボックスの必須チェック(1つ以上)
207		$('.required input[type="checkbox"]').each(function () {
208			let checkedsum;
209			let name = $( this ).attr( 'name' );
210			var $outer = $( this ).parent();
211			checkedsum = $( "input[name='" + name + "']:checked" ).length;
212			if( checkedsum > 0 ){
213				$outer.removeClass( error_class );
214				$outer.find( '.errorMsg' ).remove();
215			} else {
216				if( !$outer.hasClass( error_class ) ) {
217					$outer.addClass( error_class );
218					$outer.append( '<p class="errorMsg">' + checkbox_message + '</p>' );
219				}
220			}
221		});
222
223		// エラーがあればsubmitを停止
224		if( $( '.' + error_class ).length > 0 ){
225			var speed = 1000,
226				position = $( '.formTable .errors:first-of-type' ).offset().top,
227				headerHeight = $( 'header' ).innerHeight();
228			$( 'body , html' ).animate({ scrollTop : position - headerHeight } , speed , 'swing' );
229			return false;
230		}
231	});
232});

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.