Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular UI Bootstrap DatePicker - get selected date on close / blur

I have an ng-repeat with each row having multiple UI-Bootstrap Datepickers. I am trying to call a function in my controller when the date is selected and the picker closes. I have tried using UI-Event to capture the blur event but the model hasn't been updated when this gets called. My question is how can I get the selected date when the picker closes? Can I do something like ui-event="{ blur : 'myBlurFunction( $event, this.text)' }, or is there another way to get the data with an onClose event?

<li ng-repeat="....">
   <div ng-click="openEditStartCal($event, ticket)">
                <input ui-event="{ blur : 'blurredStartDate( $event, ticket, this.text)' }" 
                       type="text" 
                       starting-day="2" 
                       show-button-bar="false" 
                       show-weeks="false" 
                       class="form-control addTicketDateInput" 
                       datepicker-popup="dd MMM" 
                       ng-model="ticket.StartDate" 
                       is-open="startEditTicketOpened && currentTicketUpdating == ticket.TicketId" 
                       min-date="{{today()}}" 
                       max-date="'2015-06-22'" 
                       datepicker-options="dateOptions" 
                       date-disabled="disabled(date, mode)"  
                       ng-required="true" close-text="Close" />
   </div>

like image 544
Holland Risley Avatar asked Jun 22 '14 13:06

Holland Risley


3 Answers

I have solved this by using: ng-change="myChangeFunction()".

like image 71
Holland Risley Avatar answered Oct 18 '22 03:10

Holland Risley


This is possible using ng-change :

html/jsp file

 <input type="text" 
    id="StartDate" 
    name="StartDate"  
    class="form-control input-sm" 
    uib-datepicker-popup="{{format}}" 
    ng-model="StartDateVal" 
    is-open="status.opened" 
    min-date="min" 
    max-date="max"
    datepicker-options="dateOptions" 
    date-disabled="disabled(date, mode)" 
    ng-required="true"
    close-text="Close" 
    readonly="true" 
    ng-change="select(StartDateVal)" />

.js Controller

$scope.select = function(date) { 
      // here you will get updated date
};
like image 31
Riddhi Gohil Avatar answered Oct 18 '22 01:10

Riddhi Gohil


You can put a $watch in your controller for your date variable.

$scope.$watch('ticket.StartDate',function(){
  var date = $scope.ticket.StartDate;
});
like image 29
alexoviedo999 Avatar answered Oct 18 '22 03:10

alexoviedo999