protected override void OnInitialized() { if (!Checked.HasValue) { IsChecked = DefaultChecked; CheckedUncontrolled = true; } if (CascadedEditContext != null) { if (CheckedExpression == null) { throw new InvalidOperationException($"{GetType()} requires a value for the 'CheckedExpression' " + $"parameter. Normally this is provided automatically when using 'bind-Checked'."); } FieldIdentifier = FieldIdentifier.Create(CheckedExpression); if (ValidateOnInit) { CascadedEditContext.NotifyFieldChanged(FieldIdentifier); } CascadedEditContext.OnValidationStateChanged += CascadedEditContext_OnValidationStateChanged; } //IsChecked = Checked ?? DefaultChecked; //CheckedChanged.InvokeAsync(IsChecked); base.OnInitialized(); }
protected async override Task OnInternalValueChanged(TValue value) { await base.OnInternalValueChanged(value); if (CascadedEditContext != null) { CascadedEditContext.NotifyFieldChanged(FieldIdentifier); } }
protected async Task OnSelectDateInternal(SelectedDateResult result) { SelectedDate = result.Date; CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); await OnSelectDate.InvokeAsync(result); await ValueChanged.InvokeAsync(result.Date); await RangeChanged.InvokeAsync(result.SelectedDateRange); }
protected override Task OnParametersSetAsync() { FormattedDate = FormatDateInternal(SelectedDate); if (CascadedEditContext != null && ValueExpression != null) { FieldIdentifier = FieldIdentifier.Create <DateTime?>(ValueExpression); CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); CascadedEditContext.OnValidationStateChanged += CascadedEditContext_OnValidationStateChanged; } return(base.OnParametersSetAsync()); }
protected void OnSelectedDate(SelectedDateResult selectedDateResult) { //skip calendar props OnSelectedDate callback, not implemented through DatePicker SelectedDate = selectedDateResult.Date; FormattedDate = FormatDateInternal(selectedDateResult.Date); ErrorMessage = ""; CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); OnSelectDate.InvokeAsync(selectedDateResult.Date); ValueChanged.InvokeAsync(selectedDateResult.Date); CalendarDismissed(); }
protected override Task OnParametersSetAsync() { if (CascadedEditContext != null && ValueExpression != null) { //if (ValueExpression == null) //{ // throw new InvalidOperationException($"{GetType()} requires a value for the 'ValueExpression' " + // $"parameter. Normally this is provided automatically when using 'bind-Value'."); //} FieldIdentifier = FieldIdentifier.Create <DateTime>(ValueExpression); CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); CascadedEditContext.OnValidationStateChanged += CascadedEditContext_OnValidationStateChanged; } if (!isLoaded) { if (Value != DateTime.MinValue) { CurrentDate = Value; } else { CurrentDate = Today; } SelectedDate = CurrentDate; NavigatedDayDate = CurrentDate; NavigatedMonthDate = CurrentDate; IsMonthPickerVisibleInternal = ShowMonthPickerAsOverlay ? false : IsMonthPickerVisible; IsDayPickerVisibleInternal = ShowMonthPickerAsOverlay ? true : IsDayPickerVisible; GoTodayEnabled = ShowGoToToday; if (GoTodayEnabled) { GoTodayEnabled = NavigatedDayDate.Year != Today.Year || NavigatedDayDate.Month != Today.Month || NavigatedMonthDate.Year != Today.Year || NavigatedMonthDate.Month != Today.Month; } isLoaded = true; } return(base.OnParametersSetAsync()); }
protected override async Task OnParametersSetAsync() { await base.OnParametersSetAsync(); if (this.DefaultSelectedKeys != null) { foreach (var key in this.DefaultSelectedKeys) { AddSelection(key); } } if (this.DefaultSelectedOptions != null) { foreach (var option in this.DefaultSelectedOptions) { AddSelection(option.Key); } } if (ItemTemplate == null) { ItemTemplate = (item) => (builder) => { builder.OpenComponent <BFUDropdownItem>(0); builder.AddAttribute(1, "Text", item.Text); builder.AddAttribute(2, "Key", item.Key); builder.AddAttribute(3, "ItemType", item.ItemType); builder.AddAttribute(4, "Disabled", item.Disabled); builder.AddAttribute(5, "Hidden", item.Hidden); builder.CloseComponent(); }; } if (CascadedEditContext != null && (SelectedOptionExpression != null || SelectedOptionsExpression != null)) { if (SelectedOptionExpression != null) { FieldIdentifier = FieldIdentifier.Create <IBFUDropdownOption>(SelectedOptionExpression); } else { FieldIdentifier = FieldIdentifier.Create <IEnumerable <IBFUDropdownOption> >(SelectedOptionsExpression); } CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); CascadedEditContext.OnValidationStateChanged += CascadedEditContext_OnValidationStateChanged; } }
public void RemoveSelection(string key) { var option = ItemsSource.FirstOrDefault(x => x.Key == key); if (option == null) { return; } CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); if (MultiSelect) { if (!SelectedOptions.Contains(option)) { throw new Exception("This option was not already selected."); } if (OnChange.HasDelegate) { OnChange.InvokeAsync(new BFUDropdownChangeArgs(option, false)); } SelectedOptions = SelectedOptions.Where(x => x != option).ToList(); if (SelectedOptionsChanged.HasDelegate) { SelectedOptionsChanged.InvokeAsync(SelectedOptions); } } else { if (SelectedOption != null) { SelectedOption = null; if (OnChange.HasDelegate) { OnChange.InvokeAsync(new BFUDropdownChangeArgs(option, false)); } if (SelectedOptionChanged.HasDelegate) { SelectedOptionChanged.InvokeAsync(SelectedOption); } } } StateHasChanged(); }
public void ResetSelection() { //SelectedKeys.Clear(); SelectedOptions = Enumerable.Empty <IBFUDropdownOption>(); //SelectedKey = null; CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); if (MultiSelect) { if (SelectedOptionsChanged.HasDelegate) { SelectedOptionsChanged.InvokeAsync(SelectedOptions); } } else { if (SelectedOptionChanged.HasDelegate) { SelectedOptionChanged.InvokeAsync(SelectedOption); } } StateHasChanged(); }
private void ValidateTextInput() { if (IsDatePickerShown) { return; } string?inputValue = FormattedDate; if (AllowTextInput) { if (!string.IsNullOrWhiteSpace(inputValue)) { DateTime?date = DateTime.MinValue; if (SelectedDate != DateTime.MinValue && FormatDate != null && FormatDateInternal(SelectedDate) == inputValue) { return; } else { date = ParseDateFromString(inputValue); // Check if date is minvalue, or date is Invalid Date if (date == DateTime.MinValue) { // Reset invalid input field, if formatting is available if (FormatDate != null) { date = SelectedDate; FormattedDate = FormatDateInternal(date); } ErrorMessage = InvalidInputErrorMessage; } else { // Check against optional date boundaries if (IsDateOutOfBounds(date, MinDate, MaxDate)) { ErrorMessage = IsOutOfBoundsErrorMessage; } else { SelectedDate = date; ErrorMessage = ""; // When formatting is available. If formatted date is valid, but is different from input, update with formatted date // This occurs when an invalid date is entered twice if (FormatDate != null && FormatDateInternal(date) != inputValue) { FormattedDate = FormatDateInternal(date); } } } } OnSelectDate.InvokeAsync(date); ValueChanged.InvokeAsync(date); } else { ErrorMessage = IsRequired ? IsRequiredErrorMessage : ""; } CascadedEditContext?.NotifyFieldChanged(FieldIdentifier); } else if (IsRequired && string.IsNullOrWhiteSpace(inputValue)) { ErrorMessage = IsRequiredErrorMessage; } }