/** * ログイン画面フォーム */ class LoginJsForm { /** * コンストラクタ */ constructor() { /** ユーザID */ this.user_id = ""; /** パスワード */ this.password = ""; /** メッセージ */ this.message = ""; // コントロールクリア this.setControlStyle("user_id", "border: 1px solid #ccc;"); this.setControlStyle("password", "border: 1px solid #ccc;"); } /** * フォームデータを設定 */ setFormData() { var elm_user_id = document.getElementById('vol_form').user_id; if (elm_user_id != null) { this.user_id = elm_user_id.value; } var elm_password = document.getElementById('vol_form').password; if (elm_password != null) { this.password = elm_password.value; } } /** * バリデーション */ validate() { let errInfo = []; // 必須チェック if (this.user_id == "") { errInfo.push(["user_id", "ユーザIDを入力してください。"]); } if (this.password == "") { errInfo.push(["password", "パスワードを入力してください。"]); } // 桁数チェック if (errInfo.length == 0) { if (this.user_id.length > 32) { errInfo.push(["user_id", "ユーザIDの文字数が大きすぎます。"]); } if (this.password.length > 32) { errInfo.push(["password", "パスワードの文字数が大きすぎます。"]); } } // 入力形式チェック if (errInfo.length == 0) { if (validPasswd(this.password) != true) { errInfo.push(["password", "パスワードの入力形式が正しくありません。"]); } } // 範囲チェック if (errInfo.length == 0) { } // 相関チェック if (errInfo.length == 0) { } // エラー情報設定 errInfo.forEach(function(err) { this.setControlStyle(err[0], "border: 1px solid red;"); }, this); return errInfo; } /** * コントロールにスタイルを適用する */ setControlStyle(ctrlName, style) { let ctrls = document.getElementsByName(ctrlName); ctrls.forEach(function(ctrl) { ctrl.style = style; }); } }