katemihalikova / ion-datetime-picker

Date and/or time picker for awesome Ionic framework
MIT License
169 stars 101 forks source link

`only-valid` restrictions set using scope variables do not update when scope updates #93

Closed maheshwarishivam closed 7 years ago

maheshwarishivam commented 7 years ago

Is there a possibility to set the only-valid restrictions using a scope variable such that when the value of the variable changes, the restrictions also get updated.

katemihalikova commented 7 years ago

Hi there, sure it is possible. Could you share what you have done so far via codepen/plnkr/jsfiddle/whatever?

maheshwarishivam commented 7 years ago

I'm trying to do the following:

In my controller:

$scope.visitDate = new Date(); $scope.closureDate = new Date();

In my view template:

<!-- Visit Date Start -->
<ion-item>
    <span class="label">Visit Date</span>
    <div class="item-note dark datepicker" ion-datetime-picker date monday-first ng-model="visitDate">
        {{visitDate | date: "YYYY-MM-DD"}}
    </div>
    <small class="positive">(YYYY-MM-DD)</small>
</ion-item>
<!-- Visit Date End -->
<!-- Closure Date Start -->
<ion-item>
    <span class="label">Closure Date</span>
    <div class="item-note dark datepicker" ion-datetime-picker date monday-first ng-model="closureDate" only-valid="{'after': '{{visitDate}}', 'inclusive': true}">
        {{closureDate | date: "YYYY-MM-DD"}}
    </div>
</ion-item>
<!-- Closure Date End -->

Now, what I want it the only-after validation in the closureDate gets updated as soon as user selects a visitDate, but that doesn't seem to update. It stays a today's date only.

I hope that the confusion is clear.

katemihalikova commented 7 years ago

See codepen.

The restriction is updated as expected if you use only-valid="{'after': visitDate, 'inclusive': true}" - the attr is ordinary javascript object.

The second step would be to use ¨ng-change` on the first picker to check if the value of the second picker needs to be adjusted.

maheshwarishivam commented 7 years ago

It does not work for me.

Here's what I did:

katemihalikova commented 7 years ago

Sorry, seems like a wrong version of the codepen was saved before (the one with 'after': '{{visitDate}}'), try it now.