You are here: Creating a Calendar Using a Constructor: kony.ui.Calendar

Calendar Widget

Calendar widget is used to select and display dates in your application. Some scenarios in which you can leverage the features of a Calendar widget are as follows:

Here are some of features of the Calendar widget:

Customizing Cells: Personalize the various cells inside a Calendar widget. This feature allows you to customize how you want to display the selected dates, un-selected dates, and other facets of a calendar.

Setting the Location: Customize where the calendar popup should appear in an app. For instance, in a banking app, you can set the location of the Calendar popup while selecting the date of transaction.

Enabling a Range of Dates: Enable a range of dates by just setting the start date and end date. For example, in a travel application, you can use this feature to display the duration of your stay while booking a hotel.

Widgets are normally added to your Kony application using Kony Visualizer, but can also be added from code. For general information on using widgets in Visualizer, see Designing an Application in the Kony Visualizer User Guide.

For general information on this widget see the Calendar topic in the Kony Visualizer User Guide.

The Calender widget capabilities can be broadly categorized into the following:

Layout

Events Description
doLayout Invoked for every widget when the widget position and dimensions are computed.
 
PropertiesDescription
anchorPoint Specifies the anchor point of the widget bounds rectangle using the widget's coordinate space.
bottomDetermines the bottom edge of the widget and is measured from the bottom bounds of the parent container.
centerX Determines the center of a widget measured from the left bounds of the parent container.
centerY Determines the center of a widget measured from the top bounds of the parent container.
containerHeight Available only when viewType is set as CALENDAR_VIEW_TYPE_GRID_POPUP or CALENDAR_VIEW_TYPE_GRID_ONSCREEN.
containerHeightReference Available only when viewType is set as CALENDAR_VIEW_TYPE_GRID_POPUP or CALENDAR_VIEW_TYPE_GRID_ONSCREEN and when you set the containerHeight.
contentAlignment Specifies the alignment of the text for a widget with respect to its boundaries.
height Determines the height of the widget and measured along the y-axis.
maxHeight Specifies the maximum height of the widget and is applicable only when the height property is not specified.
maxWidth Specifies the maximum width of the widget and is applicable only when the width property is not specified.
minHeight Specifies the minimum height of the widget and is applicable only when the height property is not specified.
minWidth Specifies the minimum width of the widget and is applicable only when the width property is not specified.
padding Defines the space between the content of the widget and the widget boundaries.
paddingInPixelIndicates if the padding is to be applied in pixels or in percentage.
right Determines the lower right corner of the widget and is measured from the right bounds of the parent container.
topDetermines the top edge of the widget and measured from the top bounds of the parent container.
width Determines the width of the widget and is measured along the x-axis.
zIndex Specifies the stack order of a widget.
 

UI Appearance

PropertiesDescription
focusSkin Skin property that determines the look and feel when there is focus on a widget.
headerSkin Used to provide a header for the DatePicker skin, if headerText is set.
hoverSkin Specifies the look and feel of a widget when the cursor hovers on the widget.
skin Specifies a background skin for Calendar.
timeSheetSkin Specifies each cell color of the timesheet view when the calendar view type it set as CALENDAR_VIEW_TYPE_MONTH_VIEW.
viewConfigSpecifies the view configuration for different view types.
viewType Specifies the view type of the Calendar.
 
MethodsDescription
setDatesSkinAllows you to set the skin and control the look and feel of each cell in the calendar.

Animations

MethodsDescription
animate Applies an animation to the widget.
 
PropertiesDescription
transform Contains an animation transformation that can be used to animate the widget.
widgetSwipeMoveUsed to enable and configure the left or right swipe actions for a widget.

Customizing Calendar

MethodsDescription
open Allows you to open the Calendar widget's popup view dynamically.
setContext Specifies the calendar that must be displayed for the context and also helps you to position the calendar on the screen.
dismiss Allows you to dismiss the calendar widget's popup view on which the method is called.
enableRangeOfDatesAllows you to enable/disable the range of dates that fall between the startdate and enddate and disables/enables the rest of the dates.
getAppointments Used to get the appointments from the calendar view types.
navigateToNextMonth Allows you to navigate to next month of the calendar widget.
navigateToPreviousMonth Allows you to navigate to previous month of the calendar widget
switchToDate Used to switch date from the calendar view types.
 
PropertiesDescription
calendarIcon Replaces the system default calendar icon.
calendarIconAlignmentDetermines the position of the calendar icon inside the calendar input box.
calendarLanguage Used to provide a languagefor the DatePicker.
dateComponents Specifies the default date that must appear in the Date field.
dateEditable Determines whether the calendar date must be entered in the calendar textbox.
dateFormat The date format in which the selected date must appear on the display and when accessed programmatically the "date" property.
day Reads the day portion of the currently selected date.
dayTextAlignmentInCell Available only when viewType is set as CALENDAR_VIEW_TYPE_GRID_POPUP or CALENDAR_VIEW_TYPE_GRID_ONSCREEN.
displayedMonth Applicable only when viewType is set as CALENDAR_VIEW_TYPE_GRID_POPUP or CALENDAR_VIEW_TYPE_GRID_ONSCREEN.
gridThemeUsed to change the pre-defined CSS of a calendar widget.
formattedDate Currently selected data as String the format that is set through "dateFormat" property.
hideDaysHeader It indicates if the weekdays are hidden on the header for grid calendar.
hideMonthsHeader It indicates if the months header is hidden for grid calendar including the navigation buttons.
hidePreviousNextMonthDatesSpecifies the visibility of the previous and next months in a calendar.
hour Reads the hour portion of the currently selected date.
isDayVisible Specifies whether the Day combo box of the DatePicker is visible.
isMonthVisible Specifies whether the Month combo box of the DatePicker is visible.
isYearVisible Specifies whether the Year combo box of the DatePicker is visible.
minutes Reads the minutes portion of the currently selected date.
month Reads the month portion of the currently selected date.
noOfMonths Specifies the number between 1 and 12 which indicates the number of months to be displayed when the calendar is selected.
seconds Reads the seconds portion of the currently selected date.
validEndDateArray representing the day, month and year portions of the date in the same order.
validStartDate Array representing the day, month, and year portions of the date in the same order.
wheelBackgroundColor Specifies the background color for the wheel that is displayed when you click the Calendar.
year Reads the year portion of the currently selected date.
  

Data Management

MethodsDescription
clone When this method is used on a container widget, all the widgets inside the container are cloned.
clear Enables you to clear the date in the calendar and the date format is shown.
clearAppointments Used to clear existing appointments from the calendar view types.
clearData Allows you to remove the data that is set through setData method.
deleteAppointmentsAllows you to delete existing appointments or array of string consisting of unique ids that represent each appointment to any of the calendar scheduler views.
modifyAppointment Allows you to modify the existing appointment with new appointment.
removeDataAt Allows you to remove data set in a specific argument.
setDataAllows you to set new data to the widgets as specified in the widgetDataMap.
setDataAt
 
Properties

Description

data JS Objects that represents the actual data to be rendered in each cell.
inputAccessoryViewType The extra buttons (or controls) allow specific operations needed by your application, such as moving to the next or previous text field, making the keyboard disappear and so on. The area above the keyboard is known as Input Accessory View
widgetDataMapForCell Specifies the mapping information between the widget id's and the keys in the data.
 

3D Touch

MethodsDescription
registerForPeekandPop Registers a widget to enable 3D Touch peek and pop gestures.
setOnPeek Sets and overrides the existing onPeekCallback for the widget.
setOnPop Overrides the existing onPopCallback for the widget.
unregisterForPeekandPop Unregisters a widget from 3D Touch peek and pop gestures.

User Input Handling

EventsDescription
onAppointmentTap Triggered when you tap any of the existing appointments
onEmptyCellTap Triggered when you tap on any of the empty cells of the calendar day view.
onScrollWidgetPositionThis event callback is invoked by the platform when the widget location position gets changed on scrolling.
onSelection This event is triggered when an item is selected or deselected.
onTouchEnd An event callback is invoked by the platform when the user touch is released from the touch surface.
onTouchMove An event callback is invoked by the platform when the touch moves on the touch surface continuously until movement ends.
onTouchStartAn event callback is invoked by the platform when the user touches the touch surface.
 
MethodsDescription
addGestureRecognizerAllows you to set a gesture recognizer for a specified gesture for a specified widget.
removeGestureRecognizer Allows you to remove the specified gesture recognizer for the specified widget.
setGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
 
PropertiesDescription
selectedDatesSpecifies the array of dates selected when multiple dates are selected.
selectionTypeSpecifies the method of date selection in a Calendar widget.

Enabling RTL

PropertiesDescription
retainContentAlignmentHelps to retain the content alignment of the widget while applying RTL.
retainFlexPositionPropertiesHelps to retain the left, right and padding properties while applying RTL.
retainFlowHorizontalAlignmentEnables you to change the horizontal flow of the widget from left to right.

Miscellaneous

MethodsDescription
getBadge Enables you to read the badge value (if any) attached to the specified widget.
setBadge Enables you to set the badge value to the given widget at the upper, right corner of the widget.
 
PropertiesDescription
cellTemplate Available only when viewType is set as CALENDAR_VIEW_TYPE_GRID_POPUP or CALENDAR_VIEW_TYPE_GRID_ONSCREEN.
cursorTypeSpecifies the type of the mouse pointer used.
titleOnPopup Specifies the title text to be displayed on the calendar popup.
toolTip Specifies the hint text when the cursor hovers over a widget, without clicking it.
 

Configurations common to all widgets

MethodsDescription
blurEnables you to make the widget look unfocused.
convertPointFromWidgetAllows you to convert the coordinate system from a widget to a point (receiver's coordinate system).
convertPointToWidget You can convert the receiver's co-ordinate system from a point to a Widget.
removeFromParent Allows you to remove a child widget from a parent widget.
setEnabled Allows you to enable/disable a list of dates if the startdate and enddate are not set in the calendar, then this API is used to enable/disable any date in the calendar.
setEnabledAll Allows you to enable all the dates that fall between the startdate and enddate.
setFocus Specifies the widget on which there must be focus.
setVisibility Use this method to set the visibility of the widget.
 
PropertiesDescription
accessibilityConfig Enables you to control accessibility behavior and alternative text for the widget.
id Defines a string of alpha numeric characters that uniquely identifies a calendar widget within an application.
info A custom JSObject with the key value pairs that a developer can use to store the context with the widget.
isVisibleControls the visibility of a widget on the form.

Calendar Widget Basics

The calendar widget allows you to select a date from a graphical calendar. The calendar widget appears as a label with a small calendar icon (icon does not appear on Mobile Web platforms) and displays the date or the date format specified by you. You can interact with the calendar widget by clicking on it.

When the calendar widget is clicked, a grid-like calendar is displayed The calendar allows you to select a single date and move back-and-forth between months and years.

The appearance is not the same on all platforms.

Note: When the native calendar view is used, the individual dates cannot be enabled or disabled using the setEnable API. Also, when you use native calendar view, you cannot restrict the user to select the dates within the validStartDate and validEndDate range.

Creating a Calendar Using a Constructor: kony.ui.Calendar


var mycal = new kony.ui.Calendar(basicConf, layoutConf, pspConf);

Note: The configuration properties should be passed only in the respective configuration objects otherwise they are ignored.

Example

//The below function is the callback function for onSelection event
function onSelectionCallBck(calendar) {
    alert("onSelection event triggered");
}

//Defining the properties for Calendar with onSelection:onSelectionCallBck
var calBasicConf = {
    id: "calID",
    isVisible: true,
    skin: "konytextar",
    focusSkin: "calFocus",
    dateFormat: "dd/MM/yyyy",
    viewType: constants.CALENDAR_VIEW_TYPE_GRID_POPUP,
    validStartDate: [01, 01, 2012],
    validEndDate: [31, 12, 2012],
    placeholder: "JSCalendar",
    calendarIcon: "cal.png",
    onSelection: onSelectionCallBck
};

var calLayoutConf = {
    padding: [2, 2, 2, 2],
    margin: [5, 5, 5, 5],
    containerWeight: 100,
    hExpand: true,
    vExpand: true
};

var calPSPConf = {
    titleOnPopup: "calendarPopUpTitle"
};

//Creating the Calendar.
var Calendar = new kony.ui.Calendar(calBasicConf, calLayoutConf, calPSPConf);

//Reading the titleOnPopup property of calendar widget
alert("Calendar titleOnPopup ::" + Calendar.titleOnPopup);

Customizing Appearance

You can customize the appearance of the calendar widget using the following properties:

Important Considerations

The Calendar widget has the following important considerations:

DatePicker control

A new calendar control, the DatePicker, is available in Windows 10. Create this control using the Calendar viewType property value CALENDAR_VIEW_TYPE_DATEPICKER.

Calendar DatePicker native control popup

Limitations and Considerations for DatePicker Control

gridcalendar Templates

The Calendar widget provides gridcalendar templates to give you further control of the contents of a calendar cell.

What is a Template for gridcalendar?

A gridcalendar template enables you to define a template for Calendar Day cell. Only one template can be used for each Calendar. This is primarily useful for developers to achieve a customized look and feel of a Calendar Day cell.

You can define a template using the following widgets:

Where to use a gridcalendar Template

gridcalendar templates are used to achieve custom look and feel of Calendar Day cell.

The gridcalendar templates are used:

premCopyright © 2012 Kony, Inc. All rights reserved.
premCopyright © 2012 Kony, Inc. All rights reserved.