2017-08-02 5 views
0

剣道角度DatePickerの最小値と最大値を設定する必要があります。これはかなり正直で[(max)]="maxDate" and [(min)]="minDate"を使用しており、これはマウスを使用してDatePickerをクリックすると機能します。剣道角度のDatePickerの最終的なValueChangeイベントを特定するには

キーボードの入力を使用すると、ユーザーは最小および最大の日付以外の日付を選択できます。私はvalueChangeイベントを持っていますが、すべてのキーストロークで起動します。私は、ユーザーが日付全体を入力し終わった時点を決定し、必要に応じて単に日付をminまたはmaxに設定することはできません。私は次のコントロールのonFocusイベントを設定することができますが、それはクルージングです。

これは、HTMLコードの抜粋です:

<kendo-datepicker 
    id="dpFirstPaymentDate" 
    (valueChange)="onFirstPaymentDateChange($event)" 
    [(value)]="firstPaymentDate" 
    [(max)]="maxDate" 
    [(min)]="minDate" 
    [(focusedDate)]="firstPaymentDate" 
    [rangeValidation] = "true" 
    title="First Payment Date"> 
    </kendo-datepicker> 

角度コードはこれです:

protected onFirstPaymentDateChange(/*event: EventEmitter*/ value: Date): void { 

     if (value > this.maxDate) { 
      // This does not appear to be working 
      value = new Date(this.maxDate); 
      this.firstPaymentDate = new Date(this.maxDate); 
     } 
     else if (value < this.minDate) { 
      value = new Date(this.minDate); 
      this.firstPaymentDate = new Date(this.minDate); 
     } 

     this.maturityDate = new Date(value); 
     this.maturityDate.setMonth(value.getMonth() + this.term); 


    } 

完全plunkerの例はここにある:Plunker example

+0

ぼかしはどうですか?しかし、onFirstPaymentDateChangeはthis.firstPaymentDateから値を取得する必要があります。私はあなたの[plunkr](http://plnkr.co/edit/bq7xUfP9OVTwWWgHnpwi?p=preview)を少し変更しました。日付を変更して完了 –

+0

これは完璧に働いていただきありがとうございます。これを回答として追加してください、私はそれを受け入れます、 –

答えて

1

わかりました、私のコメントがあるので、実際にポイント上にあるので、実際にonchangeイベントを使用する代わりに、on blurイベントを使用する必要があります。

<kendo-datepicker 
    id="dpFirstPaymentDate" 
    (blur)="onFirstPaymentDateChange($event)" 
    [(value)]="firstPaymentDate" 
    [(max)]="maxDate" 
    [(min)]="minDate" 
    [(focusedDate)]="firstPaymentDate" 
    [rangeValidation] = "true" 
    title="First Payment Date"> 
</kendo-datepicker> 

日付の値が得られていないので、onFirstPaymentDateChange関数のちょっとした変更は、this.firstPaymentDateで取得するだけで、ロジック(最大値)を設定し続けることができます。ここに実例がありますplnkr

関連する問題