示例#1
0
        /// <inheritdoc/>
        protected override async Task OnFirstAfterRenderAsync()
        {
            object defaultDate = null;

            // for multiple mode default dates must be set as array
            if (SelectionMode != DateInputSelectionMode.Single)
            {
                defaultDate = Dates?.Select(x => FormatValueAsString(new TValue[] { x }))?.ToArray();
            }
            else
            {
                defaultDate = FormatValueAsString(new TValue[] { Date });
            }

            await JSModule.Initialize(ElementRef, ElementId, new
            {
                InputMode,
                SelectionMode  = SelectionMode.ToDateInputSelectionMode(),
                FirstDayOfWeek = (int)FirstDayOfWeek,
                DisplayFormat  = DateTimeFormatConverter.Convert(DisplayFormat),
                TimeAs24hr,
                DefaultDate = defaultDate,
                Min         = Min?.ToString(DateFormat),
                Max         = Max?.ToString(DateFormat),
                Disabled,
                ReadOnly,
                DisabledDates = DisabledDates?.Select(x => FormatValueAsString(new TValue[] { x })),
                Localization  = GetLocalizationObject()
            });

            await base.OnFirstAfterRenderAsync();
        }
示例#2
0
        /// <inheritdoc/>
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            var dateChanged           = parameters.TryGetValue <TValue>(nameof(Date), out var date) && !Date.Equals(date);
            var minChanged            = parameters.TryGetValue(nameof(Min), out DateTimeOffset? min) && !Min.IsEqual(min);
            var maxChanged            = parameters.TryGetValue(nameof(Max), out DateTimeOffset? max) && !Max.IsEqual(max);
            var firstDayOfWeekChanged = parameters.TryGetValue(nameof(FirstDayOfWeek), out DayOfWeek firstDayOfWeek) && !FirstDayOfWeek.IsEqual(firstDayOfWeek);
            var displayFormatChanged  = parameters.TryGetValue(nameof(DisplayFormat), out string displayFormat) && DisplayFormat != displayFormat;
            var timeAs24hrChanged     = parameters.TryGetValue(nameof(TimeAs24hr), out bool timeAs24hr) && TimeAs24hr != timeAs24hr;

            if (dateChanged)
            {
                var dateString = FormatValueAsString(date);

                await CurrentValueHandler(dateString);

                if (Rendered)
                {
                    ExecuteAfterRender(async() => await JSRunner.UpdateDatePickerValue(ElementRef, ElementId, dateString));
                }
            }

            if (Rendered && (minChanged || maxChanged || firstDayOfWeekChanged || displayFormatChanged || timeAs24hrChanged))
            {
                ExecuteAfterRender(async() => await JSRunner.UpdateDatePickerOptions(ElementRef, ElementId, new
                {
                    FirstDayOfWeek = new { Changed = firstDayOfWeekChanged, Value = firstDayOfWeek },
                    DisplayFormat  = new { Changed = displayFormatChanged, Value = DateTimeFormatConverter.Convert(displayFormat) },
                    TimeAs24hr     = new { Changed = timeAs24hrChanged, Value = timeAs24hr },
                    Min            = new { Changed = minChanged, Value = min?.ToString(DateFormat) },
                    Max            = new { Changed = maxChanged, Value = max?.ToString(DateFormat) },
                }));
            }

            // Let blazor do its thing!
            await base.SetParametersAsync(parameters);

            if (ParentValidation != null)
            {
                if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(DateExpression), out var expression))
                {
                    await ParentValidation.InitializeInputExpression(expression);
                }

                if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern))
                {
                    // make sure we get the newest value
                    var value = parameters.TryGetValue <TValue>(nameof(Date), out var inDate)
                        ? inDate
                        : InternalValue;

                    await ParentValidation.InitializeInputPattern(pattern, value);
                }

                await InitializeValidation();
            }
        }
        /// <inheritdoc/>
        protected override async Task OnFirstAfterRenderAsync()
        {
            await JSRunner.InitializeTimePicker(ElementRef, ElementId, new
            {
                DisplayFormat = DateTimeFormatConverter.Convert(DisplayFormat),
                TimeAs24hr,
                Default = FormatValueAsString(Time),
                Min     = Min?.ToString(Parsers.InternalTimeFormat),
                Max     = Max?.ToString(Parsers.InternalTimeFormat),
            });

            await base.OnFirstAfterRenderAsync();
        }
示例#4
0
        /// <inheritdoc/>
        protected override async Task OnFirstAfterRenderAsync()
        {
            await JSRunner.InitializeDatePicker(ElementRef, ElementId, new
            {
                InputMode,
                FirstDayOfWeek,
                DisplayFormat = DateTimeFormatConverter.Convert(DisplayFormat),
                TimeAs24hr,
                Default = FormatValueAsString(Date),
                Min     = Min?.ToString(DateFormat),
                Max     = Max?.ToString(DateFormat),
            });

            await base.OnFirstAfterRenderAsync();
        }
示例#5
0
        /// <inheritdoc/>
        protected override async Task OnFirstAfterRenderAsync()
        {
            await JSModule.Initialize(ElementRef, ElementId, new
            {
                DisplayFormat = DateTimeFormatConverter.Convert(DisplayFormat),
                TimeAs24hr,
                Default = FormatValueAsString(Time),
                Min     = Min?.ToString(Parsers.InternalTimeFormat),
                Max     = Max?.ToString(Parsers.InternalTimeFormat),
                Disabled,
                ReadOnly,
                Localization = GetLocalizationObject()
            });

            await base.OnFirstAfterRenderAsync();
        }
        /// <inheritdoc/>
        protected override async Task OnFirstAfterRenderAsync()
        {
            await JSModule.Initialize(ElementRef, ElementId, new
            {
                InputMode,
                FirstDayOfWeek,
                DisplayFormat = DateTimeFormatConverter.Convert(DisplayFormat),
                TimeAs24hr,
                Default = FormatValueAsString(Date),
                Min     = Min?.ToString(DateFormat),
                Max     = Max?.ToString(DateFormat),
                Disabled,
                ReadOnly,
                DisabledDates = DisabledDates?.Select(x => FormatValueAsString(x)),
            });

            await base.OnFirstAfterRenderAsync();
        }
示例#7
0
        /// <inheritdoc/>
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            var timeChanged          = parameters.TryGetValue(nameof(Time), out TValue time) && !Time.IsEqual(time);
            var minChanged           = parameters.TryGetValue(nameof(Min), out TimeSpan? min) && !Min.IsEqual(min);
            var maxChanged           = parameters.TryGetValue(nameof(Max), out TimeSpan? max) && !Max.IsEqual(max);
            var displayFormatChanged = parameters.TryGetValue(nameof(DisplayFormat), out string displayFormat) && DisplayFormat != displayFormat;
            var timeAs24hrChanged    = parameters.TryGetValue(nameof(TimeAs24hr), out bool timeAs24hr) && TimeAs24hr != timeAs24hr;
            var disabledChanged      = parameters.TryGetValue(nameof(Disabled), out bool disabled) && Disabled != disabled;
            var readOnlyChanged      = parameters.TryGetValue(nameof(ReadOnly), out bool readOnly) && ReadOnly != readOnly;

            if (timeChanged)
            {
                var timeString = FormatValueAsString(time);

                await CurrentValueHandler(timeString);

                if (Rendered)
                {
                    ExecuteAfterRender(async() => await JSModule.UpdateValue(ElementRef, ElementId, timeString));
                }
            }

            if (Rendered && (minChanged ||
                             maxChanged ||
                             displayFormatChanged ||
                             timeAs24hrChanged ||
                             disabledChanged ||
                             readOnlyChanged))
            {
                ExecuteAfterRender(async() => await JSModule.UpdateOptions(ElementRef, ElementId, new
                {
                    DisplayFormat = new { Changed = displayFormatChanged, Value = DateTimeFormatConverter.Convert(displayFormat) },
                    TimeAs24hr    = new { Changed = timeAs24hrChanged, Value = timeAs24hr },
                    Min           = new { Changed = minChanged, Value = min?.ToString(Parsers.InternalTimeFormat) },
                    Max           = new { Changed = maxChanged, Value = max?.ToString(Parsers.InternalTimeFormat) },
                    Disabled      = new { Changed = disabledChanged, Value = disabled },
                    ReadOnly      = new { Changed = readOnlyChanged, Value = readOnly },
                }));
            }

            // Let blazor do its thing!
            await base.SetParametersAsync(parameters);

            if (ParentValidation != null)
            {
                if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(TimeExpression), out var expression))
                {
                    await ParentValidation.InitializeInputExpression(expression);
                }

                if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern))
                {
                    // make sure we get the newest value
                    var value = parameters.TryGetValue <TValue>(nameof(Time), out var inTime)
                        ? inTime
                        : InternalValue;

                    await ParentValidation.InitializeInputPattern(pattern, value);
                }

                await InitializeValidation();
            }
        }
示例#8
0
        /// <inheritdoc/>
        public override async Task SetParametersAsync(ParameterView parameters)
        {
            var dateChanged           = parameters.TryGetValue <TValue>(nameof(Date), out var paramDate) && !Date.Equals(paramDate);
            var datesChanged          = parameters.TryGetValue(nameof(Dates), out IEnumerable <TValue> paramDates) && !Dates.AreEqual(paramDates);
            var minChanged            = parameters.TryGetValue(nameof(Min), out DateTimeOffset? paramMin) && !Min.IsEqual(paramMin);
            var maxChanged            = parameters.TryGetValue(nameof(Max), out DateTimeOffset? paramMax) && !Max.IsEqual(paramMax);
            var firstDayOfWeekChanged = parameters.TryGetValue(nameof(FirstDayOfWeek), out DayOfWeek paramFirstDayOfWeek) && !FirstDayOfWeek.IsEqual(paramFirstDayOfWeek);
            var displayFormatChanged  = parameters.TryGetValue(nameof(DisplayFormat), out string paramDisplayFormat) && DisplayFormat != paramDisplayFormat;
            var timeAs24hrChanged     = parameters.TryGetValue(nameof(TimeAs24hr), out bool paramTimeAs24hr) && TimeAs24hr != paramTimeAs24hr;
            var disabledChanged       = parameters.TryGetValue(nameof(Disabled), out bool paramDisabled) && Disabled != paramDisabled;
            var readOnlyChanged       = parameters.TryGetValue(nameof(ReadOnly), out bool paramReadOnly) && ReadOnly != paramReadOnly;
            var disabledDatesChanged  = parameters.TryGetValue(nameof(DisabledDates), out IEnumerable <TValue> paramDisabledDates) && !DisabledDates.AreEqual(paramDisabledDates);
            var selectionModeChanged  = parameters.TryGetValue(nameof(SelectionMode), out DateInputSelectionMode paramSelectionMode) && !SelectionMode.IsEqual(paramSelectionMode);

            if (dateChanged || datesChanged)
            {
                var formatedDateString = SelectionMode != DateInputSelectionMode.Single
                    ? FormatValueAsString(paramDates?.ToArray())
                    : FormatValueAsString(new TValue[] { paramDate });

                await CurrentValueHandler(formatedDateString);

                if (Rendered)
                {
                    ExecuteAfterRender(async() => await JSModule.UpdateValue(ElementRef, ElementId, formatedDateString));
                }
            }

            if (Rendered && (minChanged ||
                             maxChanged ||
                             firstDayOfWeekChanged ||
                             displayFormatChanged ||
                             timeAs24hrChanged ||
                             disabledChanged ||
                             readOnlyChanged ||
                             disabledDatesChanged ||
                             selectionModeChanged))
            {
                ExecuteAfterRender(async() => await JSModule.UpdateOptions(ElementRef, ElementId, new
                {
                    FirstDayOfWeek = new { Changed = firstDayOfWeekChanged, Value = (int)paramFirstDayOfWeek },
                    DisplayFormat  = new { Changed = displayFormatChanged, Value = DateTimeFormatConverter.Convert(paramDisplayFormat) },
                    TimeAs24hr     = new { Changed = timeAs24hrChanged, Value = paramTimeAs24hr },
                    Min            = new { Changed = minChanged, Value = paramMin?.ToString(DateFormat) },
                    Max            = new { Changed = maxChanged, Value = paramMax?.ToString(DateFormat) },
                    Disabled       = new { Changed = disabledChanged, Value = paramDisabled },
                    ReadOnly       = new { Changed = readOnlyChanged, Value = paramReadOnly },
                    DisabledDates  = new { Changed = disabledDatesChanged, Value = paramDisabledDates?.Select(x => FormatValueAsString(new TValue[] { x })) },
                    SelectionMode  = new { Changed = selectionModeChanged, Value = paramSelectionMode },
                }));
            }

            // Let blazor do its thing!
            await base.SetParametersAsync(parameters);

            if (ParentValidation != null)
            {
                if (parameters.TryGetValue <Expression <Func <TValue> > >(nameof(DateExpression), out var expression))
                {
                    await ParentValidation.InitializeInputExpression(expression);
                }

                if (parameters.TryGetValue <string>(nameof(Pattern), out var pattern))
                {
                    // make sure we get the newest value
                    var value = parameters.TryGetValue <TValue>(nameof(Date), out var inDate)
                        ? new TValue[] { inDate }
                        : InternalValue;

                    await ParentValidation.InitializeInputPattern(pattern, value);
                }

                await InitializeValidation();
            }
        }