19

こんにちは仲間のstackoverflow:ers、

MartinMilesichTimepickerプラグインと一緒にjQueryDatepickerプラグインを使用しています。日付ピッカーで日付をクリックするとウィジェットが閉じ、時間を選択する時間がないという事実を除いて、すべてがうまく機能します。

質問:日付をクリックしたときにウィジェットが閉じないようにし、代わりにユーザーに[完了]ボタン([showButtonPanel:true]オプションを有効にしたときに表示される)をクリックするか、クリックするように強制する方法があるかどうか疑問に思っています。ウィジェットの外。ユーザーがウィジェットを2回開く必要がないようにします。タイムピッカーのデモでオンラインでの動作を確認してください

この問題を解決するための助け、または正しい方向へのポインタさえもありがたいです!

詳細:Martinsダウンロードリンクから提供されたファイルを使用しています:http://milesich.com/tpdemo/timepicker-0.2.0.zip

  • jquery-ui-1.7.2.custom.min.js
  • timepicker.js(最新バージョン0.2.0)

これらは私が使用しているオプションです:

$(document).ready(function(){
    $(".datepicker").datepicker({
        duration: '',  
        showTime: true,  
        constrainInput: false,  
        stepMinutes: 5,  
        stepHours: 1, 
        time24h: true,
        dateFormat: "yy-mm-dd",
        buttonImage: '/static/images/datepicker.png',
        buttonImageOnly: true,
        firstDay: 1,
        monthNames: ['Januari','Februari','Mars','April','Maj','Juni','Juli','Augusti','September','Oktober','November','December'],
        showOn: 'both',
        showButtonPanel: true
     });
})
4

9 に答える 9

28

参考までに、そして人々が私にこれをメールで尋ねてきたので。timepicker.jsに追加する必要のあるコードチャンクは次のとおりです。

/**
 * Don't hide the date picker when clicking a date
 */
$.datepicker._selectDateOverload = $.datepicker._selectDate;
$.datepicker._selectDate = function(id, dateStr) {
    var target = $(id);
    var inst = this._getInst(target[0]);
    inst.inline = true;
    $.datepicker._selectDateOverload(id, dateStr);
    inst.inline = false;
    this._updateDatepicker(inst);
}

あなたのサイトでそれが機能するように頑張ってください!

于 2009-11-19T10:39:12.523 に答える
28

ソースを変更するのではなく、既存のイベントを使用するのが最善です

onSelect: function() {
    $(this).data('datepicker').inline = true;                               
},
onClose: function() {
    $(this).data('datepicker').inline = false;
}
于 2012-06-14T21:03:34.657 に答える
8

自分でデートピッカーをハックする必要があります。これはそれが使用するコードです。インラインでない場合は、日付を選択すると非表示になります。

独自のonSelectメソッドを渡して、datePickerインスタンスをインラインにすばやく変更してから、datepickerの内部を変更せずに元に戻すことができますが、これは非常にハッキーなソリューションです。

if (inst.inline)
        this._updateDatepicker(inst);
else {
      this._hideDatepicker(null, this._get(inst, 'duration'));
      this._lastInput = inst.input[0];
      if (typeof(inst.input[0]) != 'object')
      inst.input[0].focus(); // restore focus
      this._lastInput = null;
}
于 2009-08-10T00:01:07.447 に答える
4

ここに解決策があります:

onSelect: function ( dateText, inst ) {
    ..... // Your code like $(this).val( dateText );`


    //Set inline to true to force "no close"
    inst.inline = true;
},
onClose: function(date,inst){
    //Set inline to false => datapicker is closed
    // onClose is called only if you click outside the datapicker, onSelect will not
    // trig onClose due to inline = true
   inst.inline = false;
}

`

于 2014-01-24T12:39:52.900 に答える
3

すべてのコメントが回避策を提供するのはなぜですか?それはstraigtfarwordです:

altFieldでインラインカレンダーを使用します:)

    <input type="text" id="alternate" size="30" />
    <div id="datepicker"></div>

    <script>
       $("#datepicker").datepicker({
          altField: "#alternate"
       });
    </script>

このフィドルを確認してください:http: //jsfiddle.net/menocomp/y2s662b0/1/

于 2015-02-24T19:28:48.737 に答える
0

Emilが提案したことに続いて、selectイベントでウィジェットを閉じないことをサポートするようにウィジェットを変更するためのより良い簡単な方法を見つけました。

まず、ウィジェットのデフォルトのdictに別のプロパティを追加しました。

closeOnSelect:true //True to close the widget when you select a date

次に、_selectDateメソッドで次のステートメントを見つけます。

if (inst.inline)
        this._updateDatepicker(inst);
else {
        ...
    }

そして、次のように条件を変更します。

var closeOnSelect = this._get(inst, "closeOnSelect");        
if (inst.inline || !closeOnSelect)
        this._updateDatepicker(inst);
else {
        ...
    }

それを試してみてください、それは私のために働いています。私はJQueryUI1.8.5バージョンでそれを行いました。

于 2010-09-29T21:20:57.813 に答える
0

かっこいい、jquery-ui-1.8.5.custom.min.jsとjquery-ui.multidatespicker.jsを使用している場合は、jquery-ui-1.8.5.custom.min.jsを変更できます。

if(a.inline)this._updateDatepicker(a);

の中へ:

if(a.inline || !this._get(a, 'closeOnSelect'))this._updateDatepicker(a);
于 2010-10-13T06:53:52.583 に答える
0

まあこれは汚い回避策です...しかしそれは私にとってはうまくいきます... showButtonPanelでも:true

  $(function() {
    var dp_c = null, dp_once = false;
    $( '#datepicker' ).datepicker({
      showButtonPanel: true,
      onSelect: function() {
        $(this).data('datepicker').inline = true;  
        setTimeout(function () {
          $('#ui-datepicker-div').find('.ui-datepicker-buttonpane').append(dp_c);
        }, 1);

      },
      onClose: function() {
        $(this).data('datepicker').inline = false;
      }
    }).click(function () {
      if(!dp_once) {
        setTimeout(function () {
          dp_c = $('#ui-datepicker-div').find('.ui-datepicker-close').clone();
        }, 500);
        dp_once = !!1;
      }
    });

    $('#ui-datepicker-div').on('click', '.ui-datepicker-close', function () {
      $('#datepicker').datepicker( "hide" );
    });

  });
于 2013-06-11T07:54:42.187 に答える
0

ネイティブのjs関数をオーバーライドする必要があります。

 /* Update the input field with the selected date. */
        _selectDate: function(id, dateStr) {
            var target = $(id);
            var inst = this._getInst(target[0]);
            dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
            if (inst.input)
                inst.input.val(dateStr);
            this._updateAlternate(inst);
            var onSelect = this._get(inst, 'onSelect');
            if (onSelect)
                onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);  // trigger custom callback
            else if (inst.input)
                inst.input.trigger('change'); // fire the change event
            if (inst.inline)
                this._updateDatepicker(inst);
            else {
                if(inst.settings.hideOnSelect != false){
                    this._hideDatepicker();
                }
                this._lastInput = inst.input[0];
                if (typeof(inst.input[0]) != 'object')
                    inst.input.focus(); // restore focus
                this._lastInput = null;
            }
        },

そして、例として、datepicker構成に適切なオプションを追加します。

var defaultDatePickerOptions = {
        hideOnSelect: false,
        ...
    }; 
 var birthDate = jQuery.extend({}, defaultDatePickerOptions);
 $('#birthdate').datepicker(birthDate);
于 2013-12-20T11:55:41.943 に答える