1.0.3 • Published 7 years ago

sm-daterangepicker v1.0.3

Weekly downloads
186
License
MIT
Repository
github
Last release
7 years ago

sm-daterangepicker - AngularJS (directive)

The daterangepicker component of bootstrap: http://www.daterangepicker.com/, as directive for use with AngularJS.

sm-daterangepicker

Installation

npm install --save sm-daterangepicker

Attention You have imported the bootstrap css into the project so that the date component is rendered correctly.

Use

Add in the module of your application:

require("sm-daterangepicker"); //return module name
angular.module("yourModuleName", ["sm-daterangepicker"]);
ou
angular.module("yourModuleName", [require("sm-daterangepicker")]);

After adding, just use the policy as follows:

<input type="text" ng-model="yourVariable" sm-daterangepicker>

ngModel

To get the beginning and end date, just get the date of the object in the model, formatted like this:

//ngModel
{
    startDate: [object Moment],
    endDate: [object Moment]
}

//Controller
$scope.yourVariable.startDate
$scope.yourVariable.endDate

Available Attributes

AttributeTypeDescription
envStringPass this attribute with "DEV", and soon the component will log everything that is changed. (It receives by default "PROD", however it picks up from node.js if it is "DEV")
localeObjectDefinition of the translation, if you do not have in the project the angular provider translate. (If no translation is passed it assigns by default the English language.)
date-timeStringAccepts values 24h or 12h, to indicate the format, when declared displays in the input the time.
yearDate/MomentIt receives only a date, and it makes a limit of the beginning of the year until the end of the year, that contains in her. (When passed this parameter it ignores the minimum and maximum date)
start-dateDate/MomentSets the selected start date.
end-dateDate/MomentSet as the preset end date.
min-dateDate/MomentSets the minimum date.
max-dateDate/MomentSets the maximum deadline.
date-limitStringLimits a range by days, months, years, or hours, minutes, and seconds.
onshowFunctionTriggered when the calendar is shown.
onhideFunctionTriggered when the calendar is closed.
onapplyFunctionTriggered when the apply button is clicked, or when a predefined interval is clicked.
oncancelFunctionTriggered when the cancel button is clicked.
suffix-translationStringNamespace used in the translation provider's rendering file translate.

Run-time update

Variables of minimum, maximum, beginning, end, and year can all be changed at runtime, and the date component has already adapted to change.

Locale

Note: There are two ways to translate the daterangepicker, one is passing the locale attribute, with the following object:

Attribute locale

//Model
$scope.localeObject = {
    format: "MM/DD/YYYY H:mm",
    separator: " -- ",
    applyLabel: "Apply",
    cancelLabel: "Cancel",
    fromLabel: "From",
    toLabel: "To",
    customRangeLabel: "Custom",
    daysOfWeek: [   
                    "Su",
                    "Mo",
                    "Tu",
                    "We",
                    "Th",
                    "Fr",
                    "Sa"
                ],
    monthNames: [   
                    "January",
                    "February",
                    "March",
                    "April",
                    "May",
                    "June",
                    "July",
                    "August",
                    "September",
                    "October",
                    "November",
                    "December"
                ],
    firstDay: "1"
}
//View
<input type="text" locale="localeObject" sm-daterangepicker>

Another way to do translation that is more efficient by supporting multiple languages and changing at runtime is by working with the provider angular translate.

Angular translate

To better understand what I am explaining below, read about the angular translate.


Namespace (Optional): <input type="text" suffix-translation="NAMESPACE" sm-daterangepicker>

file_of_translation.js

"SM_DATERANGEPICKER: {}" ou "NAMESPACE.SM_DATERANGEPICKER: {}"

"SM_DATERANGEPICKER": {
    "FORMAT": "MM/DD/YYYY H:mm",
    "SEPARATOR": " -- ",
    "APPLYLABEL": "Apply",
    "CANCELLABEL": "Cancel",
    "FROMLABEL": "From",
    "TOLABEL": "To",
    "CUSTOMRANGELABEL": "Custom",
    "DAYSOFWEEK": {
        "SU": "Su",
        "MO": "Mo",
        "TU": "Tu",
        "WE": "We",
        "TH": "Th",
        "FR": "Fr",
        "SA": "Sa"
    },
    "MONTHNAMES": {
        "JANUARY": "January",
        "FEBRUARY": "February",
        "MARCH": "March",
        "APRIL": "April",
        "MAY": "May",
        "JUNE": "June",
        "JULY": "July",
        "AUGUST": "August",
        "SEPTEMBER": "September",
        "OCTOBER": "October",
        "NOVEMBER": "November",
        "DECEMBER": "December"
    },
    "FIRSTDAY": "1"
}

Date limit

Using the date-limit attribute is not that complicated, what it does just, is to make a limit of the date selected from the limited range, just pass it the following:

<input type="text" date-limit="parameter:value" sm-daterangepicker>
//Supported parameters: days, months, years, hours, minutes and seconds.
//For more than one parameter passed, separate them with a comma.
//Example: parameter:value,parameter:value...

Read in another language

Clique aqui e leia em português

Contribution

Contribute to the fact that daterangepicker directive is getting better and better. Just download the project and apply your changes, and after that it will be analyzed to be approved.

Licence

MIT