フォーム内容をSalesforceに連携した際に、
日付にNullのレコードが含まれているとエラー通知が届きます。
ただ必須項目ではなく任意項目のまま進めたいので、
項目がnullや空白だった場合、
裏で、デフォルト値を入れてエラーを回避したいです。
またツールの仕様で、formタグのsubmitイベントやinput(type=submit)のclickイベントを設定できません。
対策としてこちらのフォーマットにすることなのですが、はめてできないでしょうか。
JavaScript
1//登録フォームの確認画面(submitボタンのname値が__commit)のサンプルコード 2<script> 3 var submitFormCustomFunc = function (button_name, exec_submit){ 4 if (button_name === "__back") { 5 // 戻るボタンが押された処理を書く 6 alert("戻るボタンが押されました"); 7 exec_submit(); 8 } else if (button_name === "__commit") { 9 // 送信ボタンが押された処理を書く 10 alert("送信ボタンが押されました"); 11 exec_submit(); 12 } 13} 14</script>
ソースはこちらです。
HTML
1<form action="/tykz2/m" method="post" autocomplete="off"> 2 <table class=""> 3 <tr class=""> 4 <th id="th_33">日付</th> 5 <td id="td_33"> 6 7 <select name="e_33[year]" id="select_year"> 8 <option value="">年</option> 9 <option value="2022">2022年</option> 10 <option value="2023">2023年</option> 11 </select> 12 13 <select name="e_33[month]" id="select_month"> 14 <option value="">月</option> 15 <option value="1">01月</option> 16 <option value="2">02月</option> 17 </select> 18 19 <select name="e_33[day]" id="select_day"> 20 <option value="">日</option> 21 <option value="1">01日</option> 22 <option value="2">02日</option> 23 <option value="3">03日</option> 24 <option value="4">04日</option> 25 </select> 26 27 </td> 28 </tr> 29 </table> 30 31<div class="box" id="b9"> 32<input type="submit" name="__send" id=".__send" value="確認画面へ" /> 33</div> 34</form> 35コード
JavaScript
1 document.getElementById('.__send').addEventListener('click', function(){ 2 3 var select_year = document.getElementById('select_[year]').value; 4 var select_month = document.getElementById('select_[month]').value; 5 var select_day = document.getElementById('select_[day]').value; 6 7 if (select_year == null || select_year == '') { 8 select_year = "1"; 9 } 10 if (select_month == null || select_month == '') { 11 select_month = "1"; 12 } 13 if (select_day == null || select_day == '') { 14 select_day = "1"; 15 } 16 17}); 18コード
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/07 03:27
2022/07/07 03:43
2022/07/07 04:06
2022/07/07 04:23
2022/07/07 05:41