2017-02-22 4 views
1

次のフォームがレンダリングされており、最初のクリック時にsubmit buttonを無効にしてユーザーが継続してクリックしないようにしたいと考えています。可能であれば、私は送信ボタンメッセージがNodeJs Expressのボタンを無効にする方法は?

以下

お待ちください...

ビューコードがあるに

を行って

イムから変更したいです

<!-- Send email and update user --> 
       <form method="post" action="/delivery/chooseBoxSelectedEmailUpdate"> 
        <input type="hidden" name="boxCommand" value="{{command}}"> 
        <input type="hidden" name="boxComport" value="{{comport}}"> 
        <input type="hidden" name="boxCubbyId" value="{{cubbyId}}"> 
        <input type="hidden" name="boxId" value="{{boxId}}"> 
        <input type="hidden" name="userHashtag" value="{{userHashtag}}"> 

        <button class="btn-primary-full" type="submit"> 
         <i class="fa fa-cube" aria-hidden="true"></i> 
         &nbsp;I'm done 
        </button> 
       </form> 
01以下

は、簡単のは<span/>タグでそれをラップさせ、ボタンのテキストを検索できるようにするためのレンダリングコード

res.render('delivery/chooseBoxSelectedOpened', { 
     title: 'Layoverbox', 
     helpButtonURL: '/help/help-dropPackage', 
     helpButtonTitle: 'Help', 
     boxComport: comport, 
     boxCommand: command, 
     cubbyId: rows[i].cubby_id, 
     boxId: boxSelectedValue 

    }); 

答えて

1

HTML

です。

<button class="btn-primary-full" type="submit"> 
    <i class="fa fa-cube" aria-hidden="true"></i> 
    &nbsp;<span>I'm done</span> 
</button> 

はJavaScript

私はあなたのフォームのonsubmitハンドラを書かれていると仮定しています。

送信ボタンをクリックすると、AJAXリクエストを行う前に、送信ボタンのテキストを無効にして設定します。

AJAXリクエストの返信が届いたら、successまたはcompleteハンドラで、送信ボタンのテキストを有効にしてリセットします。

$(function() { 
    $(document).on('submit', 'form', function (e) { 
     e.preventDefault(); 
     // find and cache submit button within the form 
     var button = $('button[type=submit]', this); 
     // disable and set the text 
     button.prop('disabled', true).find('span').text("Please wait..."); 
     // make AJAX call 
     $.ajax({ 
      // etc 
      success: function (data) { 
       button.prop('disabled', false).find('span').text("I'm done"); 
      } 
     }) 
    }); 
}); 
+0

あなたはonsubmitハンドラをどういう意味ですか?ビューはhbsによってレンダリングされますか? onsubmit = "formSubmit()"のような – John

+0

? – John

+0

フォーム内の送信ボタンをクリックすると、ブラウザはデフォルトでフォームデータを送信し、URL(フォームの 'action'属性で指定)にリダイレクトします。あなたのページが消えてしまうので、後であなたがページ上で行うことは役に立たない。 **フォーム**を送信した後も同じページに留まるためには、あなたの 'form'要素に[' onsubmit'イベント](http://help.dottoro.com/ljppxrti.php)を添付する必要があります。 AJAXを使用してフォームを送信してください。 – Mikey

関連する問題