2016-07-25 6 views
1

私は下のリンクからjquery-confirmスクリプトを使用しています。ダイアログボックス内にフォームフィールドを含めることができます。下のリンクの "Prompt Like Prompt"の青色のボタンをクリックすると、これを見ることができます。jQueryの確認ダイアログ内のjQuery UI datepicker

私はフォーム(1つのフィールド)を設定していますが、この入力を日付ピッカーにしたいと思います。このフォームはjavascriptをどこに置く必要があるのか​​分かりませんダイアログが生成されるまで存在します。

https://craftpip.github.io/jquery-confirm/

私のダイアログのjavascript:form.txtの

  $('.deal_edit').on('click', function() { 
      var id = $(this).attr('data-id'); 
      $.confirm({ 
       title: 'Change end Date', 
       content: 'url:form.txt', 
       confirm: function() { 
        var input = this.$b.find('input#new_end_date').val(); 
        var errorText = this.$b.find('.text-danger'); 
        if (input.val() == '') { 
         errorText.show(); 
         return false; 
        } else { 
         var data = {action: 'edit_deal', id: id, new_date: new_date}; 
         $.post('ajax.php', data, function(response) { 

          $.alert({ 
           title: "Updated", 
           content: "Ok, record has been updated - this page will reload.", 
           confirm: function() { 
            location.reload(); 
           } 
          }); 

         }); 
        } 
       } 
      }); 
      return false; 
     });  

内容:

<p>The only editable field currently is 'deal end date'. (This may change soon)</p> 
<div class="form-group"> 
    <label>New End Date</label> 
    <input autofocus type="text" id="new_end_date" name="new_end_date" class="form-control"> 
</div> 
    <p class="text-danger" style="display:none">Please enter an end date, or click 'close'.</p> 

ありがとうございました!!!

+0

HTMLコード全体を貼り付けることができますか? 'deal-edit' class divが見つかりません –

+0

取引編集は単なるリンクです。 – drumichael611

答えて

1

私は同じ問題を抱えていました。これは私がそれを修正する方法です。

あなたはプラグインがダイアログウィンドウを作成した後に呼び出される関数のように、onContentReadyイベントにコードを追加することができます開く時のイベントを追加する必要があると

 $.confirm({ 
      onOpen: function(){ 
       $(".datepicker").datepicker(); 
      }, 
      onClose: function(){ 
       $(".datepicker").datepicker("destroy"); 
      }, 
      title: 'Change end Date', 
      content: 'url:form.txt', 
      confirm: function() { 
       var input = this.$b.find('input#new_end_date').val(); 
       var errorText = this.$b.find('.text-danger'); 
       if (input.val() == '') { 
        errorText.show(); 
        return false; 
       } else { 
        var data = {action: 'edit_deal', id: id, new_date: new_date}; 
        $.post('ajax.php', data, function(response) { 

         $.alert({ 
          title: "Updated", 
          content: "Ok, record has been updated - this page will reload.", 
          confirm: function() { 
           location.reload(); 
          } 
         }); 

        }); 
       } 
      } 
     }); 
+0

すばらしい解決策!ありがとう – drumichael611

0

を追加するには、確認ダイアログにOnCloseの。あなたの例にこのコードを追加することができます

onContentReady: function() { 
    $("#new_end_date").datetimepicker(); 
}