fragaria / angular-daterangepicker

Angular.js wrapper for dangrossman/bootstrap-daterangepicker
MIT License
519 stars 372 forks source link

how to fire an function when click on apply function #138

Closed himanshugoyal5734 closed 5 years ago

himanshugoyal5734 commented 8 years ago

i am not able to fire the function on apply function from two days ...can anybody help me to resolve this issue???

nirmalgoswami commented 8 years ago

@himanshugoyal5734 apply.daterangepicker: Triggered when the apply button is clicked

vishwajeetsonkar commented 6 years ago

it is not working it tried it.

nirmalgoswami commented 6 years ago

Check document, following information copied from document

Optionally, event handlers can be passed in through the eventHandlers attribute of options.

<input date-range-picker class="form-control date-picker" type="text" ng-model="date"
options="{eventHandlers: {'apply.daterangepicker': function(ev, picker) { ... }}}"/>

All event handlers from the Bootstrap daterangepicker are supported. For reference, the complete list is below:

apply.daterangepicker: Triggered when the apply button is clicked

cancel.daterangepicker: Triggered when the cancel button is clicked

vishwajeetsonkar commented 6 years ago

hey @nirmalgoswami thanks for that now that it is working I need to create my own locale calendar in the ranges where a user is allowed to select only 7 days from whichever date they select but dont know how to do that

nirmalgoswami commented 6 years ago
$scope.options = {
      applyClass: 'btn-green',
      locale: {
        applyLabel: "Apply",
        fromLabel: "From",
        format: "YYYY-MM-DD", //will give you 2017-01-06
    //format: "D-MMM-YY", //will give you 6-Jan-17
    //format: "D-MMMM-YY", //will give you 6-January-17
        toLabel: "To",
        cancelLabel: 'Cancel',
        customRangeLabel: 'Custom range'
      },
      ranges: {
        'Last 7 Days': [moment().subtract(6, 'days'), moment()],

      }
    }

Just keep 7 days in ranges object if you want to show only 7 days range

and if you want to restrict user to select only 7 days based on start date then use following code

<input date-range-picker type="text" ng-model="date" max="addDays(date, 7)" />

vishwajeetsonkar commented 6 years ago

@nirmalgoswami can you plz explain me the second approach