public override void initState() { base.initState(); _mode = widget.initialCalendarMode; _currentDisplayedMonthDate = new DateTime(widget.initialDate.Year, widget.initialDate.Month, 1); _selectedDate = widget.initialDate; }
void _handleChangeMode(DatePickerMode value) { if (value != this.mode) { this.onModeChanged(value); } }
public _DatePickerDialog( Key key = null, DateTime?initialDate = null, DateTime?firstDate = null, DateTime?lastDate = null, DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar, material_.SelectableDayPredicate selectableDayPredicate = null, string cancelText = null, string confirmText = null, string helpText = null, DatePickerMode initialCalendarMode = DatePickerMode.day, string errorFormatText = null, string errorInvalidText = null, string fieldHintText = null, string fieldLabelText = null ) : base(key: key) { D.assert(initialDate != null); D.assert(firstDate != null); D.assert(lastDate != null); initialDate = utils.dateOnly(initialDate.Value); firstDate = utils.dateOnly(firstDate.Value); lastDate = utils.dateOnly(lastDate.Value); D.assert( !lastDate.Value.isBefore(firstDate.Value), () => $"lastDate {lastDate} must be on or after firstDate {firstDate}." ); D.assert( initialDate == null || !initialDate.Value.isBefore(firstDate.Value), () => $"initialDate {initialDate} must be on or after firstDate {firstDate}." ); D.assert( initialDate == null || !initialDate.Value.isAfter(lastDate.Value), () => $"initialDate {initialDate} must be on or before lastDate {lastDate}." ); D.assert( selectableDayPredicate == null || initialDate == null || selectableDayPredicate(initialDate.Value), () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate." ); this.initialDate = initialDate.Value; this.firstDate = firstDate.Value; this.lastDate = lastDate.Value; this.initialEntryMode = initialEntryMode; this.selectableDayPredicate = selectableDayPredicate; this.cancelText = cancelText; this.confirmText = confirmText; this.helpText = helpText; this.initialCalendarMode = initialCalendarMode; this.errorFormatText = errorFormatText; this.errorInvalidText = errorInvalidText; this.fieldHintText = fieldHintText; this.fieldLabelText = fieldLabelText; }
internal _DatePickerModeToggleButton( DatePickerMode mode, string title, VoidCallback onTitlePressed ) { this.mode = mode; this.title = title; this.onTitlePressed = onTitlePressed; }
public _DatePickerHeader( DateTime selectedDate, DatePickerMode mode, ValueChanged <DatePickerMode> onModeChanged, Orientation orientation, Key key = null ) : base(key: key) { this.selectedDate = selectedDate; this.mode = mode; this.onModeChanged = onModeChanged; this.orientation = orientation; }
void _handleModeChanged(DatePickerMode mode) { this._vibrate(); this.setState(() => { this._mode = mode; if (this._mode == DatePickerMode.day) { // SemanticsService.announce(localizations.formatMonthYear(_selectedDate), textDirection); } else { // SemanticsService.announce(localizations.formatYear(_selectedDate), textDirection); } }); }
public _DatePickerDialog( DateTime initialDate, DateTime firstDate, DateTime lastDate, SelectableDayPredicate selectableDayPredicate, DatePickerMode initialDatePickerMode, Key key = null ) : base(key: key) { this.initialDate = initialDate; this.firstDate = firstDate; this.lastDate = lastDate; this.selectableDayPredicate = selectableDayPredicate; this.initialDatePickerMode = initialDatePickerMode; }
void _handleYearChanged(DateTime value) { _vibrate(); if (value < widget.firstDate) { value = widget.firstDate; } else if (value > widget.lastDate) { value = widget.lastDate; } setState(() => { _mode = DatePickerMode.day; _handleMonthChanged(value); }); }
void _handleModeChanged(DatePickerMode mode) { _vibrate(); setState(() => { _mode = mode; // if (_mode == DatePickerMode.day) { // SemanticsService.announce( // _localizations.formatMonthYear(_selectedDate), // _textDirection, // ); // } else { // SemanticsService.announce( // _localizations.formatYear(_selectedDate), // _textDirection, // ); // } }); }
public static IPromise <object> showDatePicker( BuildContext context, DateTime initialDate, DateTime firstDate, DateTime lastDate, SelectableDayPredicate selectableDayPredicate = null, DatePickerMode initialDatePickerMode = DatePickerMode.day, Locale locale = null, TransitionBuilder builder = null ) { D.assert(initialDate >= firstDate, () => "initialDate must be on or after firstDate"); D.assert(initialDate <= lastDate, () => "initialDate must be on or before lastDate"); D.assert(firstDate <= lastDate, () => "lastDate must be on or after firstDate"); D.assert( selectableDayPredicate == null || selectableDayPredicate(initialDate), () => "Provided initialDate must satisfy provided selectableDayPredicate" ); D.assert(context != null); D.assert(MaterialD.debugCheckHasMaterialLocalizations(context)); Widget child = new _DatePickerDialog( initialDate: initialDate, firstDate: firstDate, lastDate: lastDate, selectableDayPredicate: selectableDayPredicate, initialDatePickerMode: initialDatePickerMode ); if (locale != null) { child = Localizations.overrides( context: context, locale: locale, child: child ); } return(DialogUtils.showDialog( context: context, builder: (BuildContext _context) => { return builder == null ? child : builder(_context, child); } )); }
public CalendarDatePicker( Key key = null, DateTime?initialDate = null, DateTime?firstDate = null, DateTime?lastDate = null, ValueChanged <DateTime> onDateChanged = null, ValueChanged <DateTime> onDisplayedMonthChanged = null, DatePickerMode initialCalendarMode = DatePickerMode.day, material_.SelectableDayPredicate selectableDayPredicate = null ) : base(key: key) { D.assert(initialDate != null); D.assert(firstDate != null); D.assert(lastDate != null); initialDate = utils.dateOnly(initialDate.Value); firstDate = utils.dateOnly(firstDate.Value); lastDate = utils.dateOnly(lastDate.Value); D.assert(onDateChanged != null); D.assert(initialCalendarMode != null); this.onDateChanged = onDateChanged; this.onDisplayedMonthChanged = onDisplayedMonthChanged; this.initialCalendarMode = initialCalendarMode; this.selectableDayPredicate = selectableDayPredicate; D.assert( !(this.lastDate < this.firstDate), () => $"lastDate {lastDate} must be on or after firstDate {firstDate}." ); D.assert( !(this.initialDate < this.firstDate), () => $"initialDate {initialDate} must be on or after firstDate {firstDate}." ); D.assert( !(this.initialDate > this.lastDate), () => $"initialDate {initialDate} must be on or before lastDate {lastDate}." ); D.assert( selectableDayPredicate == null || selectableDayPredicate(this.initialDate), () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate." ); }
void _handleYearChanged(DateTime value) { if (value < this.widget.firstDate) { value = this.widget.firstDate; } else if (value > this.widget.lastDate) { value = this.widget.lastDate; } if (value == this._selectedDate) { return; } this._vibrate(); this.setState(() => { this._mode = DatePickerMode.day; this._selectedDate = value; }); }
internal static void InitializeExtenders(MaskedEditExtender maskedEditExtender, CalendarExtender calendarExtender, string format, DatePickerMode mode, string mask) { maskedEditExtender.AcceptAMPM = true; maskedEditExtender.ClearMaskOnLostFocus = true; maskedEditExtender.CultureName = CultureInfo.CurrentCulture.Name; // Setup format string if (string.IsNullOrEmpty(format)) { if (mode == DatePickerMode.Date) { calendarExtender.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; maskedEditExtender.MaskType = MaskedEditType.Date; var dateMask = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; dateMask = Regex.Replace(dateMask, "\\w", "9"); dateMask = Regex.Replace(dateMask, "\\W", "/"); maskedEditExtender.Mask = dateMask; } else if (mode == DatePickerMode.Time) { calendarExtender.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern; maskedEditExtender.MaskType = MaskedEditType.Time; var timeMask = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern; timeMask = Regex.Replace(timeMask, @"(?<1>\w)(?<!\k<1>\k<1>)(?!\k<1>)", @"$1$1"); timeMask = Regex.Replace(timeMask, "\\w", @"9"); timeMask = Regex.Replace(timeMask, "\\W", @":"); maskedEditExtender.Mask = timeMask; } else { calendarExtender.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern + " " + CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern; maskedEditExtender.MaskType = MaskedEditType.DateTime; var dateMask = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; dateMask = Regex.Replace(dateMask, "\\w", "9"); dateMask = Regex.Replace(dateMask, "\\W", "/"); var timeMask = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern; timeMask = Regex.Replace(timeMask, @"(?<1>\w)(?<!\k<1>\k<1>)(?!\k<1>)", @"$1$1"); timeMask = Regex.Replace(timeMask, "\\w", @"9"); timeMask = Regex.Replace(timeMask, "\\W", @":"); maskedEditExtender.Mask = string.Format("{0} {1}", dateMask, timeMask); } } else { calendarExtender.Format = format; if (mode == DatePickerMode.Date) { maskedEditExtender.MaskType = MaskedEditType.Date; } else if (mode == DatePickerMode.Time) { maskedEditExtender.MaskType = MaskedEditType.Time; } else { maskedEditExtender.MaskType = MaskedEditType.DateTime; } if (string.IsNullOrEmpty(mask)) { maskedEditExtender.Enabled = false; } else { maskedEditExtender.Mask = mask; } } }
public static MvcHtmlString DatePickerFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, DatePickerMode dateType, object htmlAttributes, int stepMinute = 1) { Func <TModel, TProperty> methodCall = expression.Compile(); TProperty value = methodCall(htmlHelper.ViewData.Model); var inputName = ExpressionHelper.GetExpressionText(expression); return(htmlHelper.DatePicker(inputName, value, dateType, htmlAttributes, stepMinute)); }
public static MvcHtmlString DatePicker(this HtmlHelper htmlHelper, string name, object date, DatePickerMode dateType, object htmlAttributes, int stepMinute = 1) { string displayValue = string.Empty, cssClass = string.Empty; string maskSeperator = "."; if (CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern.Contains("/")) { maskSeperator = "/"; } DateTime?dateValue = Convert.ToDateTime(date); string funcName = "datepicker"; var mask = string.Empty; switch (dateType) { case DatePickerMode.DateAndTime: cssClass = "date-time-picker"; if (dateValue.Value > DateTime.MinValue) { displayValue = string.Format("{0} {1}", dateValue.Value.ToString(HtmlHelpersResource.DatePickerDatePattern), dateValue.Value.ToString(HtmlHelpersResource.DatePickerTimePattern)); } funcName = "datetimepicker"; mask = string.Format("99{0}99{0}9999 99:99", maskSeperator); break; case DatePickerMode.Date: cssClass = "date-picker"; if (dateValue.Value > DateTime.MinValue) { displayValue = dateValue.Value.ToString(HtmlHelpersResource.DatePickerDatePattern); } mask = string.Format("99{0}99{0}9999", maskSeperator); break; case DatePickerMode.Time: cssClass = "time-picker"; if (dateValue.Value > DateTime.MinValue) { displayValue = dateValue.Value.ToString(HtmlHelpersResource.DatePickerTimePattern); } funcName = "timepicker"; mask = "99:99"; break; case DatePickerMode.MonthYearOnly: cssClass = "date-picker"; if (dateValue.Value > DateTime.MinValue) { displayValue = dateValue.Value.ToString(HtmlHelpersResource.DatePickerMonthYearOnlyPattern); } mask = string.Format("99{0}9999", maskSeperator); break; } #region Init javascript var sb = new StringBuilder(); sb.AppendFormat("<script language='javascript'>"); sb.AppendFormat("$().ready(function() {{"); sb.AppendLine(); sb.AppendFormat("$('#{0}').{1}({{", name, funcName); sb.Append("autoFocusNextInput: true, "); sb.AppendFormat("dateFormat: '{0}', ", dateType == DatePickerMode.MonthYearOnly?HtmlHelpersResource.DatePickerJavascriptMonthYearOnlyPattern: HtmlHelpersResource.DatePickerJavascriptDatePattern); sb.AppendFormat("timeFormat: '{0}', ", HtmlHelpersResource.DatePickerJavascriptTimePattern); sb.Append("buttonImage: '/Content/img/common/calendar.png', "); sb.Append("showButtonPanel: true, "); sb.Append("changeYear: true, "); sb.AppendFormat("stepMinute: {0}, ", stepMinute); sb.Append("showOn: 'button', "); sb.Append("firstDay: 1"); sb.AppendFormat("}});"); sb.AppendLine(); sb.AppendFormat("$('#{0}').mask('{1}');", name, mask); sb.AppendLine(); sb.AppendFormat("$('#{0}').bind('change', function () {{", name); sb.AppendFormat("$(this).validateDate({{type: {0}, ", (int)dateType); sb.AppendFormat("dateformat: '{0}'}});", HtmlHelpersResource.DatePickerJavascriptDatePattern); sb.AppendFormat(" }});"); sb.AppendLine(); sb.AppendFormat(" }});"); sb.AppendFormat("</script>"); #endregion return(MvcHtmlString.Create(string.Format("<div class='{0}'>{1}{2}</div>", cssClass, htmlHelper.TextBox(name, displayValue, htmlAttributes), sb))); }
public static Future <DateTime> showDatePicker( BuildContext context, DateTime initialDate, DateTime firstDate, DateTime lastDate, DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar, material_.SelectableDayPredicate selectableDayPredicate = null, string helpText = null, string cancelText = null, string confirmText = null, Locale locale = null, bool useRootNavigator = true, RouteSettings routeSettings = null, TextDirection?textDirection = null, TransitionBuilder builder = null, DatePickerMode initialDatePickerMode = DatePickerMode.day, string errorFormatText = null, string errorInvalidText = null, string fieldHintText = null, string fieldLabelText = null ) { D.assert(context != null); initialDate = utils.dateOnly(initialDate); firstDate = utils.dateOnly(firstDate); lastDate = utils.dateOnly(lastDate); D.assert( !lastDate.isBefore(firstDate), () => $"lastDate {lastDate} must be on or after firstDate {firstDate}." ); D.assert( !initialDate.isBefore(firstDate), () => $"initialDate {initialDate} must be on or after firstDate {firstDate}." ); D.assert( !initialDate.isAfter(lastDate), () => $"initialDate {initialDate} must be on or before lastDate {lastDate}." ); D.assert( selectableDayPredicate == null || selectableDayPredicate(initialDate), () => $"Provided initialDate {initialDate} must satisfy provided selectableDayPredicate." ); D.assert(initialEntryMode != null); D.assert(initialDatePickerMode != null); D.assert(material_.debugCheckHasMaterialLocalizations(context)); Widget dialog = new _DatePickerDialog( initialDate: initialDate, firstDate: firstDate, lastDate: lastDate, initialEntryMode: initialEntryMode, selectableDayPredicate: selectableDayPredicate, helpText: helpText, cancelText: cancelText, confirmText: confirmText, initialCalendarMode: initialDatePickerMode, errorFormatText: errorFormatText, errorInvalidText: errorInvalidText, fieldHintText: fieldHintText, fieldLabelText: fieldLabelText ); if (textDirection != null) { dialog = new Directionality( textDirection: textDirection.Value, child: dialog ); } if (locale != null) { dialog = Localizations.overrides( context: context, locale: locale, child: dialog ); } return(material_.showDialog <DateTime>( context: context, useRootNavigator: useRootNavigator, routeSettings: routeSettings, builder: (BuildContext subContext) => { return builder == null ? dialog : builder(subContext, dialog); } )); }