前提
laravel8にて勤怠管理アプリ作成中です。
フォームのボタンにjavaScriptを用いてbladeファイル読み込み時
に条件分岐にてdisable属性を使用してオンオフ制御をしたいのですが、うまく機能しません。
実現したいこと
勤怠ページに勤務開始、休憩開始、休憩終了、勤務終了4つのボタン
があります。
勤怠ページ読み込み→jsにて勤務開始のみクリック可能に
↓
勤務開始クリック→コントローラにてDBに現在時刻を打刻→適当な変数に値を入れる→
変数を持って最初のページにリダイレクト
↓
勤怠ページ読み込み、変数に値が入っていれば勤務終了と休憩開始のみクリック可能に
といった具合にdisable制御を機能させようとしています。
発生している問題・エラーメッセージ
勤務開始のみ実装して動作確認をしてる段階ですが、うまく機能せず
原因が特定できていない状況です。
jsのコードは継承のbladeに直書きです。
そもそもjavascriptが正しく機能していないのでしょうか。
該当のソースコード
javascript
1document.addEventListener('DOMContentLoaded',function() { 2 3 var start = @json($start); 4 var end = @json($end); 5 var rest_start = @json($rest_start); 6 var rest_end = @json($rest_end); 7 8 const startButton = document.getElementById('startButton'); 9 const endButton = document.getElementById('endButton'); 10 const restInButton = document.getElementById('restInButton'); 11 const restOutButton = document.getElementById('restOutButton'); 12 13 endButton.disabled = true; 14 restInButton.disabled = true; 15 restOutButton.disabled = true; 16 17 if(!empty($start)){ 18 startButton.disabled = true; 19 endButton.disabled = false; 20 restInButton.disabled = false; 21 } 22 },false); 23 24```blade.php(フォームボタン部分) 25<div class="button-box"> 26 <div class="top-button"> 27 <form action="/work_start" method="POST" class="button-form" name="start"> 28 @csrf 29 <button type="submit" id="startButton" >勤務開始</button> 30 </form> 31 <form action="/work_end" method="POST" name="end"> 32 @csrf 33 <button type="submit" id="endButton" >勤務終了</button> 34 </form> 35 </div> 36 <div class="bottom-button"> 37 <form action="/rest_start" method="POST" name="rest-start"> 38 @csrf 39 <button type="submit" id="restInButton" >休憩開始</button> 40 </form> 41 <form action="/rest_end" method="POST" name="rest-end"> 42 @csrf 43 <button type="submit" id="restOutButton" >休憩終了</button> 44 </form> 45 </div> 46 </div> 47 48### 試したこと 49 50 51### 補足情報(FW/ツールのバージョンなど) 52 53ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。