`

移动端安卓和IOS开发框架Framework7教程-Calendar / Datepicker

阅读更多

Calendar is a touch optimized component that provides an easy way to handle dates.

Calendar could be used as inline component or as overlay. Overlay Calendar will be automatically converted to Popover on tablets (iPad).

Create Calendar Instance

Calendar can be created and initialized only using JavaScript. We need to use related App's method:

myApp.calendar(parameters) - initialize Calendar with parameters

  • parameters - object - object with Calendar parameters. Required.
  • Method returns initialized Calendar instance

For example:

  1. var myCalendar = app.calendar({
  2.     input: '#calendar-input'
  3. });
复制

Calendar Parameters

Let's look on list of all available parameters:

Parameter Type Default Description Common Picker Modal Component ParametersSpecific Picker ParametersCallbacks
container string or HTMLElement   String with CSS selector or HTMLElement where to place generated Calendar HTML. Use only for inline pickers
input string or HTMLElement   String with CSS selector or HTMLElement with related input element
scrollToInput boolean true Scroll viewport (page-content) to input when calendar opened
inputReadOnly boolean true Sets "readonly" attribute on specified input
convertToPopover boolean true Converts calendar modal to Popover on large screens (on iPad)
onlyOnPopover boolean false Enable it and Calendar will be always opened in Popover
cssClass string   Additional CSS class name to be set on calendar modal
toolbar boolean true Enables calendar modal toolbar
toolbarCloseText string 'Done' Text for Done/Close toolbar button
toolbarTemplate string   Toolbar HTML Template. By default it is HTML string with following template:
  1. <div class="toolbar">
  2.   <div class="toolbar-inner">
  3.     {{monthPicker}}
  4.     {{yearPicker}}
  5.   </div>
  6. </div>
复制
 
value array   Array with initial selected dates. Each array item represents selected date
formatValue function (p, values)   Function to format input value, should return new/formatted string value. values is array where each item represents selected date
monthNames array ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August' , 'September' , 'October', 'November', 'December'] Array with full month names
monthNamesShort array ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] Array with short month names
dayNames array ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] Array with week day names
dayNamesShort array ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] Array with week day short names
updateValuesOnTouchmove boolean true Updates picker and input values during touch move
firstDay number 1 First day of the week. By default 1 - Monday
weekendDays array [0, 6] Array with index numeber of weekend days, by default it is Saturday and Sunday
dateFormat string 'yyyy-mm-dd' Default date format, available expressions:
  • 'yyyy' - 4 digits year
  • 'yy' - 2 digits year
  • 'mm' - 2 digits month number, from 01 to 12
  • 'm' - month number, from 1 to 12
  • 'MM' - full month name
  • 'M' - short month name
  • 'dd' - 2 digits day number, from 01 to 31
  • 'd' - day number, from 1 to 31
  • 'DD' - full week day name
  • 'D' - short week day name
multiple boolean false Enable to allows select multiple dates/values
direction string 'horizontal' Months layout direction, could be 'horizontal' or 'vertical'
minDate Date null Minimum allowed date
maxDate Date null Maximum allowed date
touchmove boolean true If enabled then calendar months slides follow finger during touch move
animate boolean true Enables transition between months
closeOnSelect boolean false Enable and calendar will be closed when user pick a date
weekHeader boolean true Enable week header with short name week days
monthPicker boolean true Enable month picker in toolbar
monthPickerTemplate string   Month picker HTML template. By default it is:
  1. <div class="picker-calendar-month-picker">
  2.     <a href="#" class="link icon-only picker-calendar-prev-month">
  3.         <i class="icon icon-prev"></i>
  4.     </a>
  5.     <span class="current-month-value"></span>
  6.     <a href="#" class="link icon-only picker-calendar-next-month">
  7.         <i class="icon icon-next"></i>
  8.     </a>
  9. </div>
复制
 
yearPicker boolean true Enable year picker in toolbar
yearPickerTemplate string   Year picker HTML template. By default it is:
  1. <div class="picker-calendar-year-picker">
  2.     <a href="#" class="link icon-only picker-calendar-prev-year">
  3.         <i class="icon icon-prev"></i>
  4.     </a>
  5.     <span class="current-year-value"></span>
  6.     <a href="#" class="link icon-only picker-calendar-next-year">
  7.         <i class="icon icon-next"></i>
  8.     </a>
  9. </div>
复制
 
onChange function (p, values, displayValues)   Callback function that will be executed when picker value changed. values anddisplayValues are arrays where each item represents value/display value of related column
onMonthAdd function (p, monthContainer)   Callback function that will be executed when newly generated month HTML element will be added to calendar.
onDayClick function (p, dayContainer, year, month, day)   Callback function that will be executed when user clicks/select any date
onMonthYearChangeStart function (p, year, month)   Callback function that will be executed in the beginning of transition to another month/year
onMonthYearChangeEnd function (p, year, month)   Callback function that will be executed in the end of transition to another month/year
onOpen function (p)   Callback function that will be executed when picker is opened
onClose function (p)   Callback function that will be executed when picker is closed

Calendar Methods & Properties

After we initialize Calendar we have its initialized instance in variable (like myCalendar variable in example above) with helpful methods and properties:

PropertiesMethods
myCalendar.params Object with passed initialization parameters
myCalendar.value Array where each item represents selected date
myCalendar.opened true if Calendar is currently opened
myCalendar.inline true if Calendar is inline Calendar
myCalendar.cols Array with specified Calendar columns. Each column also has its own methods and properties (look below)
myCalendar.container Dom7 instance with Calendar HTML container
myCalendar.setValue(values) Set new selected dates. values is array where each item represents selected date
myCalendar.nextMonth(duration) Calendar transition to next month for specified duration in ms
myCalendar.prevMonth(duration) Calendar transition to previous month for specified duration in ms
myCalendar.nextYear() Calendar transition to next year
myCalendar.prevYear() Calendar transition to previous year
myCalendar.setYearMonth(year, month, duration) Calendar transition to specified year, month for specified duration in ms
myCalendar.open() Open Calendar
myCalendar.close() Close Calendar
myCalendar.destroy() Destroy Calendar instance and remove all events

Access to Calendar's Instance

If you initialize Calendar as inline Calendar it is possible to access to Calendar's instance from its HTML container

  1. var myCalendar = $$('.calenadr-inline')[0].f7Calendar;
复制

Examples

实例预览

Default Setup

  1. <div class="content-block-title">Default setup</div>
  2. <div class="list-block">
  3.   <ul>
  4.     <li>
  5.       <div class="item-content">
  6.         <div class="item-inner">
  7.           <div class="item-input">
  8.             <input type="text" placeholder="Your birth date" readonly id="calendar-default">
  9.           </div>
  10.         </div>
  11.       </div>
  12.     </li>
  13.   </ul>
  14. </div>
复制

 

  1. var calendarDefault = myApp.calendar({
  2.     input: '#calendar-default',
  3. });
复制

Custom Date Format

  1. <div class="content-block-title">Custom date format</div>
  2. <div class="list-block">
  3.   <ul>
  4.     <li>
  5.       <div class="item-content">
  6.         <div class="item-inner">
  7.           <div class="item-input">
  8.             <input type="text" placeholder="Select date" readonly id="calendar-date-format">
  9.           </div>
  10.         </div>
  11.       </div>
  12.     </li>
  13.   </ul>
  14. </div>
复制
  1. var calendarDateFormat = myApp.calendar({
  2.     input: '#calendar-date-format',
  3.     dateFormat: 'DD, MM dd, yyyy'
  4. });
复制

Multiple Values

  1. <div class="content-block-title">Multiple Values</div>
  2. <div class="list-block">
  3.   <ul>
  4.     <li>
  5.       <div class="item-content">
  6.         <div class="item-inner">
  7.           <div class="item-input">
  8.             <input type="text" placeholder="Select multiple dates" readonly id="calendar-multiple">
  9.           </div>
  10.         </div>
  11.       </div>
  12.     </li>
  13.   </ul>
  14. </div>
复制
  1. var calendarMultiple = myApp.calendar({
  2.     input: '#calendar-multiple',
  3.     dateFormat: 'M dd yyyy',
  4.     multiple: true
  5. });
复制

Inline With Custom Toolbar

  1. <div class="content-block-title">Inline with custom toolbar</div>
  2. <div class="content-block">
  3.   <div style="padding:0; margin-right:-15px; width:auto" class="content-block-inner">
  4.     <div id="calendar-inline-container"></div>
  5.   </div>
  6. </div>
复制
  1. var $$ = Dom7;
  2. var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August' , 'September' , 'October', 'November', 'December'];
  3.  
  4. var calendarInline = myApp.calendar({
  5.     container: '#calendar-inline-container',
  6.     value: [new Date()],
  7.     weekHeader: false,
  8.     toolbarTemplate: 
  9.         '<div class="toolbar calendar-custom-toolbar">' +
  10.             '<div class="toolbar-inner">' +
  11.                 '<div class="left">' +
  12.                     '<a href="#" class="link icon-only"><i class="icon icon-back"></i></a>' +
  13.                 '</div>' +
  14.                 '<div class="center"></div>' +
  15.                 '<div class="right">' +
  16.                     '<a href="#" class="link icon-only"><i class="icon icon-forward"></i></a>' +
  17.                 '</div>' +
  18.             '</div>' +
  19.         '</div>',
  20.     onOpen: function (p) {
  21.         $$('.calendar-custom-toolbar .center').text(monthNames[p.currentMonth] +', ' + p.currentYear);
  22.         $$('.calendar-custom-toolbar .left .link').on('click', function () {
  23.             calendarInline.prevMonth();
  24.         });
  25.         $$('.calendar-custom-toolbar .right .link').on('click', function () {
  26.             calendarInline.nextMonth();
  27.         });
  28.     },
  29.     onMonthYearChangeStart: function (p) {
  30.         $$('.calendar-custom-toolbar .center').text(monthNames[p.currentMonth] +', ' + p.currentYear);
  31.     }
  32. });
复制

 

1
0
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

    iOS开发 - 第02篇 - UI进阶 - 06 - DatePicker

    在iOS开发中,UI设计是用户体验的关键部分,而DatePicker作为一种常用的UI组件,常用于日期和时间的选择,如在创建一个简单的点菜选择界面、国旗选择或生日选择等场景。本篇我们将深入探讨如何使用DatePicker来实现...

    jquery-ui-datepicker中文版

    &lt;script src="js/jquery.ui.datepicker-zh-CN.js"&gt;&lt;/script&gt; 去掉该行,全英文。格式也好了很多! 期待后续的高手修改 该资源来自于网上一哥们 &lt;script type="text/javascript" src="js/jquery-ui-timepicker-addon...

    jquery-ui-1.11.2日期控件datepicker

    最新jquery-ui-1.11.2日期控件,官网下载内涵图片和自己添加的中文辅助jquery-ui-timepicker-zh-CN.js,经过本人测试绝对可以用,不知道怎么用的百度上找个例子即可,需要导入的包 &lt;link rel="stylesheet" type="text/...

    react-modern-calendar-datepicker:适用于React的现代,美观,可自定义的日期选择器

    安装 :rocket:npm i react-modern-calendar-datepicker# or if you prefer Yarn:yarn add react-modern-calendar-datepicker文献资料 :page_facing_up: 您可以上找到文档 该文档分为几个部分:实用工具不同地区打字...

    bootstrap-datepicker1.9.0.zip

    这个压缩包"bootstrap-datepicker1.9.0.zip"包含了版本1.9.0的源代码和其他相关资源,使得开发者能够轻松地在Bootstrap框架基础上实现日期输入的交互增强。以下是关于这个插件的详细知识点: 1. **Bootstrap集成**...

    material-calendar-datepicker:适用于Android的简单材料日历DatePicker

    简单的 Android Material 日历 DatePicker 简单的 Android 材料日历 DatePicker 为您提供所示的日期选择器,但非常简单,具有简单的 API。 该库使用作为基础,并对其进行了调整,使其尽可能接近 Material Design ...

    react-native-calendar-datepicker:React-Native跨平台,日历组件

    这是一个具有自定义外观的快速工作示例:安装npm install --save react-native-calendar-datepicker 最小React本机:“ ^ 0.33.0”基本用法使用此组件非常容易。 但是,最初的外观是极简主义的,但是该库为开发人员...

    前端项目-vuejs-datepicker.zip

    vuejs-datepicker适应各种屏幕尺寸,确保在桌面端和移动端都有良好的用户体验。 7. **可配置选项**:vuejs-datepicker提供丰富的配置选项,如设置默认日期、设定日期范围、控制时间选择等,以满足不同项目的多样化...

    日历控件只有年和月-------datepicker修改版

    1.增加参数 showDay,默认值是true,true的情况下,就是含有日的情况,跟原来的datepicker无区别,只要年和月,请在参数里添加 showDay:false,如下 : $('#selMonth').datepicker( { showOn: "both", buttonImage...

    前端项目-foundation-datepicker.zip

    这个插件是专门针对Foundation框架设计的,Foundation是一个流行的响应式前端框架,用于构建可访问、灵活且响应迅速的网站和应用。基金会日期选择器(Foundation Datepicker)旨在与Foundation的其他组件无缝集成,...

    semantic-ui-calendar-react:Datepicker React组件基于语义UIReact组件

    Datepicker React组件基于语义UIReact组件 我的意图是创建类似于。 在这里您可以找到一个实时示例 安装 npm npm i semantic-ui-calendar-react CDN &lt; script src =" ...

    bootstrap-datepicker实现只能选择每一年的某一个月份

    Bootstrap是世界上最受欢迎的前端开发框架之一,用于构建响应式、移动优先的网页项目。它包含了一系列组件和插件,帮助开发者快速创建美观且功能丰富的网页界面。在本篇中,我们将详细探讨如何利用Bootstrap的日期...

    修改Jquery-UI-DatePicker-可以选择时间

    &lt;script src="js/jquery.ui.datepicker-zh-CN.js"&gt;&lt;/script&gt; 去掉此行,样式好很多。中文版的版式需要高手完善 来自于网上一高手 &lt;script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"&gt;&lt;/script...

    对Android和iOS的React Native DatePicker组件具有相同的显示效果-JavaScript开发

    React Native DatePicker component for both Android and iOS having the same display effect react-native-datepicker React Native DatePicker component for both Android and iOS having the same display ...

    bootstrap-datepicker-1.9.0_bootstrap源码_

    Bootstrap是世界上最流行的前端开发框架之一,它为开发者提供了丰富的组件和样式,用于快速构建响应式、移动优先的网站。在本资源中,我们关注的是`bootstrap-datepicker-1.9.0`,这是一个针对Bootstrap框架的日期...

    jquery-ui-datepicker

    《jQuery UI Datepicker:实现多样化日期选择效果》 在网页开发中,日期选择器是一个常见的交互元素,用于方便用户输入日期。jQuery UI 提供了一个功能强大的日期选择器插件 —— `jquery-ui-datepicker`,它可以...

    react-native-jalali-datepicker::calendar:适用于Android和iOS的React Native Jalali DatePicker组件:sparkles:

    React本地贾拉利日期选择器预习安装包管理器命令纱yarn add @mohamadkh75/react-native-jalali-datepicker npm npm i --save @mohamadkh75/react-native-jalali-datepicker用法import DatePicker from '@mohamadkh75...

    react-native-calendarview-datepicker::herb: React-native-calendar-date-picker 组件

    React-native-calendarview-datepicker :package: 安装 npm i react-native-calendarview-datepicker 或者 yarn add react-native-calendarview-datepicker :television: 预习 :rocket: 基本用法 默认 您可以...

    vue-hotel-datepicker:Vue日期范围选择器组件

    npm install vue-hotel-datepicker PNPM pnpm install vue-hotel-datepicker 纱 yarn add vue-hotel-datepicker import HotelDatePicker from 'vue-hotel-datepicker' import 'vue-hotel-datepicker/dist/...

    ios14-webview-datepicker-issue

    ios14-webview-datepicker-issue 复制步骤: 在iOS 14设备或模拟器上运行WebviewCalenderIssue项目。 最初,网页不应是垂直滚动的(尝试滚动时会反弹,但不会看到滚动条)。 单击第一个文本字段,这将弹出键盘...

Global site tag (gtag.js) - Google Analytics