0.0.1 • Published 7 years ago

openui5-flatpickr v0.0.1

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
7 years ago

openui5-flatpickr

openui5-flatpickr is a SAPUI5 Custom Control that wraps flatpickr Date Picker

flatpickr example with time support

Demo

You can checkout a demo with different configurations here: https://stermi.github.io/openui5-flatpickr/test/demo/

Usage

Configure manifest.json

Add the library to sap.ui5 dependencies list and configure the resourceRoots to point where you uploaded the custom library.

"sap.ui5": {
    ...
	"dependencies": {
		"minUI5Version": "1.30.0",
		"libs": {
    		...
			"it.designfuture.flatpickr": {}
		}
	},
	"resourceRoots": {
		"it.designfuture.flatpickr": "./thirdparty/it/designfuture/flatpickr/"
	}
}

Add the custom control inside an XML View

First of all add the namespace

xmlns:df="it.designfuture.flatpickr"

And than you can simply add it a simple Input (FlatDatePicker extends InputBase)

<df:FlatDatePicker 
  class="sapUiMediumMargin"
  clickOpens="false"
  dateFormat="d/m/Y"
/>

Parameters

NameTypeDefaultDescription
altFormatstring"F j, Y"Exactly the same as date format, but for the altInput field
altInputbooleanfalseShow the user a readable date (as per altFormat), but return something totally different to the server
altInputClassstring""This class will be added to the input element created by the altInput option. Note that altInput already inherits classes from the original input
allowInputbooleanfalseAllows the user to enter a date directly input the input field. By default, direct entry is disabled
clickOpensbooleanfalseWhether clicking on the input should open the picker. You could disable this if you wish to open the calendar manually with.open()
dateFormatstring"Y-m-d"A string of characters which are used to define how the date will be displayed in the input box. The supported characters are defined in the table below.
dateValueobjectnullSet the initial selected date. Same as preloading a date string into an input's value attribute, but can also handle a Date object
hourValueint12Initial value of the hour element
minuteValueint0Initial value of the minute element
disabledDatesobject[][]Arrays of dates object to be disabled
disableMobilebooleanfalseSet disableMobile to true to always use the non-native picker. By default, Flatpickr utilizes native datetime widgets unless certain options (e.g. disable) are used
enabledDatesobject[][]Arrays of dates object to be enabled
enableTimebooleanfalseEnables time picker
enableSecondsbooleanfalseEnables seconds in the time picker
hourIncrementint1Adjusts the step for the hour input (incl. scrolling)
inlinebooleanfalseDisplays the calendar inline
maxDateobjectnullThe maximum date that a user can pick to (inclusive).
minDateobjectnullThe minimum date that a user can start picking from (inclusive)
minuteIncrementint5Adjusts the step for the minute input (incl. scrolling)
modestring"single""single", "multiple", or "range"
noCalendarbooleanfalseHides the day selection in calendar. Use it along with enableTime to create a time picker
shorthandCurrentMonthbooleanfalseShow the month using the shorthand version (ie, Sep instead of September)
staticbooleanfalsePosition the calendar inside the wrapper and next to the input element. (Leave false unless you know what you're doing.)
time_24hrbooleanfalseDisplays time picker in 24 hour mode without AM/PM selection when enabled
weekNumbersbooleanfalseEnables display of week numbers in calendar

Events

NameDescription
onChangeonChange gets triggered when the user selects a date, or changes the time on a selected date
onOpenonOpen gets triggered when the calendar is opened
onCloseonClose gets triggered when the calendar is closed
onMonthChangeonMonthChange gets triggered when the month is changed, either by the user or programmatically
onYearChangeonYearChange gets triggered when the year is changed, either by the user or programmatically
onReadyonReady gets triggered once the calendar is in a ready state
onValueUpdateonValueUpdate gets triggered when the input value is updated with a new date string
onDayCreateTake full control of every date cell with the onDayCreate() hook

Methods

NameDescription
clearDatePickerResets the selected dates (if any) and clears the input
openDatePickerShows/opens the calendar
closeDatePickerCloses the calendar
destroyDatePickerDestroys the Flatpickr instance, cleans up - removes event listeners, restores inputs, etc
formatDateReturn a formatted date
jumpToDateSets the calendar view to the year and month ofdate, which can be a date string, a Date, or nothing. If date is undefined, the view is set to the latest selected date, the minDate, or today’s date
parseDateParses a date string or a timestamp, and returns a Date
redrawDatePickerRedraws the calendar. Shouldn’t be necessary in most cases
setDateSets the current selected date(s) todate, which can be a date string, a Date, or an Array of the Dates. Optionally, pass true as the second argument to force any onChange events to fire
toggleDatePickerShows/opens the calendar if its closed, hides/closes it otherwise
getSelectedDatesReturn an array with selected dates

Build

If you would like to extend and customize the controllr, you can easily do that but re-building the code with just a simple Grunt command:

npm install
grunt build

You just need to take note of two things:

  1. compatVersion: you should type here your project SAPUI5 version. Old projects (1.28.x) will generate a library-preload.json, new version will instead create a library-prelaod.js
  2. openui5_theme: add addictional files for each theme you are supporting in your application

Credits

Emanuele Ricci

License

This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details