2016-12-23 11 views
0

私は自分のビューにdatepickerを使用しています。私はangularjsも使用します。問題は、私がOKボタンを使用してもそれがNGモデルの状態を変更しないということです。それでもng-emptyが表示されます。別のフィールドを計算するのにこの値を使用しますが、無視することができます。 onCloseではなくokボタンをどのようにアクティブにすることができますか?ユーザーが月と年を選択するときにngモデルが変更されていることを確認する必要があります。 私の日付ピッカー:。 enter image description hereJquery datepickerボタンがうまく機能しない

$(function() { 
      $('.date-picker').datepicker({ 

       yearRange: "-5:+0", 
       showButtonPanel: true, 
       dateFormat: 'MM yy', 
       changeMonth: true, 
       changeYear: true, 
       closeText: 'OK', 
       beforeShow: function() { 
        $(this).datepicker('widget').addClass('hide-calendar'); 
        if ((selDate = $(this).val()).length > 0) { 
         iYear = selDate.substring(selDate.length - 4, selDate.length); 
         iMonth = jQuery.inArray(selDate.substring(0, selDate.length - 5), $(this).datepicker('option', 'monthNames')); 
         $(this).datepicker('option', 'defaultDate', new Date(iYear, iMonth, 1)); 

         $(this).datepicker('setDate', new Date(iYear, iMonth, 1)); 
        } 
       }, 
       onClose: function (dateText, inst) { 
        $(this).datepicker('widget').removeClass('hide-calendar'); 
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val(); 
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val(); 
        $(this).datepicker('setDate', new Date(year, month, 1)); 

        var monthNames = ["January", "February", "March", "April", "May", "June", 
          "July", "August", "September", "October", "November", "December" 
        ]; 

        var mN = $("#monthNo").val(); 

        if (mN == '') { 
         return; 

        } 

        var tm = parseInt(month) + parseInt(mN-1) 
        if (tm > 11) { 
         tm = tm - 12; 
         year =parseInt(year) + 1; 
        } 

        $("#to").val(monthNames[parseInt(tm)] + " " + year); 
       } 


      }).click(function() { 
       $('.ui-datepicker-calendar').hide(); 
      }).attr("readonly", true); 
     }); 
+0

私を助けることができます@Bharti Sharma – Fawel

+0

datepickerは、クリックして$ scopeを実行する必要があるモデルを更新します$ apply() – alphapilgrim

+0

どこに$ scopeを実装できますか$ apply()? – Fawel

答えて

-1

$スコープ$(適用)が冗長です。 $ scope。$ digest()を試してください。しかし、jqueryのプラグインは常に角度の問題がたくさんある/角度プラグインを使用しようとする/それはあなたの将来の多くの時間を節約する

+0

デートピッカーのjquery UIのような角型プラグインはありますか? @ dimm d – Fawel

+0

1つの角度プラグインにはディレクティブラッパーがありますが、jquery UI Pickerは非常に重いです。このhttps://github.com/search?o=desc&q=datepicker+angular&s=stars&type=Repositories&utf8=%E2%9C%93の1つを試してみてください –

関連する問題