//////////////////////////////////////////////////////////////////////////////////////////////////// /// \fn private void TextBox_Selected_KeyUp(object sender, KeyEventArgs e) /// /// \brief Event handler. Called by TextBox_Selected for key up events. /// /// \par Description. /// /// \par Algorithm. /// - If CR was pressed - start a new item insertion /// - If the text is part of an existing item - select that item /// - Else put the text in a new item /// /// \par Usage Notes. /// /// \author Ilanh /// \date 29/11/2017 /// /// \param sender (object) - Source of the event. /// \param e (KeyEventArgs) - Key event information. //////////////////////////////////////////////////////////////////////////////////////////////////// private void TextBox_Selected_KeyUp(object sender, KeyEventArgs e) { string text = TextBox_Selected.Text; if (e.Key == Key.Enter) { // If the text does not exist in the list - add it to the list bool textInListBox = false; foreach (ListBoxItem item in ListBox_Options.Items) { if ((string)item.Content == text) { textInListBox = true; break; } } if (!textInListBox) { ListBoxItem item = new ListBoxItem(); item.Content = text; ListBox_Options.Items.Add(item); disableSelectedItemEvent = true; ListBox_Options.SelectedItem = item; disableSelectedItemEvent = false; } // Create a new empty item TextBox_Selected.Text = ""; newItem = new ListBoxItem(); newItem.Content = ""; return; } // For all other inputs // Remove the new item from the list // If the new item string is part of an existing item - mark this item // Else Add the new item to the list disableSelectedItemEvent = true; ListBox_Options.Items.Remove(newItem); foreach (ListBoxItem item in ListBox_Options.Items) { if (((string)item.Content).IndexOf(text) == 0) { ListBox_Options.SelectedItem = item; return; } } newItem.Content = text; ListBox_Options.Items.Add(newItem); ListBox_Options.SelectedItem = newItem; NewItemCreated?.Invoke(null, null); disableSelectedItemEvent = false; }
protected override void BuildRenderTree(RenderTreeBuilder builder) { if (!CreateItemOptions.IsCreateItemAllowed || !PermissionContext.HasCreateItemPermission) { return; } base.BuildRenderTree(builder); var internalBuilder = new BlazorRendererTreeBuilder(builder); var createItemContext = new CreateItemContext(CreateItemOptions, CreateFormCssClasses); createItemContext.OnItemCreated += (object sender, ItemCreatedArgs e) => NewItemCreated?.Invoke(e); internalBuilder .OpenElement(HtmlTagNames.Div, "modal") .AddAttribute(HtmlAttributes.Id, CreateItemOptions.CreateItemModalName) .AddAttribute("role", "dialog") .OpenElement(HtmlTagNames.Div, $"modal-dialog modal-dialog-centered {CreateFormCssClasses.ModalSize}") .AddAttribute(HtmlAttributes.Id, CreateItemOptions.CreateItemModalSizeDiv) .OpenElement(HtmlTagNames.Div, "modal-content") .OpenElement(HtmlTagNames.Div, CreateFormCssClasses.ModalHeader) .OpenElement(HtmlTagNames.H4, "modal-title") .AddContent("Create Item") .CloseElement() .OpenElement(HtmlTagNames.Button, "close") .AddAttribute(HtmlJSEvents.OnClick, BindMethods.GetEventHandlerValue((UIMouseEventArgs e) => FlexGridInterop.HideModal(CreateItemOptions.CreateItemModalName))) .AddAttribute(HtmlAttributes.Type, "button") .AddAttribute("data-dismiss", "modal") .AddAttribute("aria-label", "Close") .OpenElement(HtmlTagNames.Span) .AddAttribute(HtmlAttributes.AriaHidden, "true") .AddContent(new MarkupString("×")) .CloseElement() .CloseElement() .CloseElement() .OpenElement(HtmlTagNames.Div, CreateFormCssClasses.ModalBody) .OpenComponent(typeof(CreateItemForm <,>) .MakeGenericType(CreateItemOptions.ModelType, CreateItemOptions.OutputDtoType)) .AddAttribute(nameof(CreateItemContext), createItemContext) .CloseComponent() .CloseElement() .CloseElement() .CloseElement() .CloseElement(); }