フォームで、入力ヶ所にクリックをして入力がアクティブになった状態
でEnterキーを押下すると以下のコードのregist関数が実行されてしまい困っています。
<html> <body> <form method="POST" action="hearing_account.php" id="order_form" name="order_form" class="h-adr" onsubmit="return false;"> <div class="form_area"> <div class="form_column"> <label class="form_label">条件1<span class="required">必須</span></label> <div class="form_input row"> <div class="form_radio" v-for="(radio_flg_option, index) in radio_flg_options"> <label class="" :key="index"> <input class="" type="radio" :value="radio_flg_option.value" name="recording_flg" v-model="recording_flg" > {{ radio_flg_option.label }} </label> </div> </div> </div> <div class="mt_big"> 以下の入力をお願いします。★問題のInputはこちらです。 </div> <div class="form_column"> <label class="form_label">アドレス<span class="required">必須</span></label> <div v-for="(address,index) in addresses" class="ip form_column_sub"> <div class="input_num_area"> {{ index + 1 }} </div> <div class="input_address_area"> <input type="text" v-model="addresses[index]" class="form_parts" name="addresses[]" > </div> </div> <div class="ip_btn_area"> <span class=""> <button type="button" @click="addInput" class="insert_btn">追加</button> </span> <span class=""> <button type="button" @click="removeInput" class="delete_btn">削除</button> </span> </div> </div> </div> <div id="form_submit"> <button class="button center_button" @click="regist">登録</button> </div> </form> <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script> <script> new Vue({ el: '#app', data: { errors: [], radio_flg_options: [ {label: 'あり', value: 1}, {label: 'なし', value: 0}, ], recording_flg: "", addresses: ['',], input_num: 1, }, watch: { }, mounted: function() { }, computed: { }, methods: { removeInput: function() { if(this.input_num > 1) { this.addresses.splice(this.input_num-1, 1); // 該当するデータを削除 this.input_num = this.input_num - 1; } }, addInput: function() { this.input_num = this.input_num + 1; if(this.input_num <= 20) { this.addresses.push(''); // 配列に1つ空データを追加する } }, regist: function(e) { //★発火してしまうのはこちらの関数です。 this.errors = []; if(this.recording_flg === "") { this.errors.push("情報1をご選択ください。"); } if(this.oft_flg === "") { this.errors.push("情報1をご選択ください。"); } if(this.out_flg === "") { this.errors.push("情報3をご選択ください。"); } //バリデーションOKの時 if(this.errors.length == 0) { document.order_form.submit(); } }, } }); </script> </body> </html>
onsubmit="return false;"
を入れいているので、ページリロード後などEnterを押下してもregist関数は発火しませんが、
入力欄をクリックしてアクティブ状態でEnterキーを押下するとregist関数が発火してしまい困っております…
アドバイスいただけますと幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/05/10 09:32