From 0bbfc1e8c766b379b7fec63e5138e2cefa44cbae Mon Sep 17 00:00:00 2001 From: Marin Bratanov Date: Sun, 11 Jul 2021 12:57:43 +0300 Subject: [PATCH 1/2] kb(inputs): how to use FocusAsync --- knowledge-base/inputs-set-focus.md | 73 ++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 knowledge-base/inputs-set-focus.md diff --git a/knowledge-base/inputs-set-focus.md b/knowledge-base/inputs-set-focus.md new file mode 100644 index 0000000000..49d034303c --- /dev/null +++ b/knowledge-base/inputs-set-focus.md @@ -0,0 +1,73 @@ +--- +title: Focus input +description: How to focus a blazor input or textbox +type: how-to +page_title: Focus input or textbox +slug: inputs-kb-focus +position: +tags: +ticketid: 1527317 +res_type: kb +--- + +## Environment + + + + + + + +
Product Version2.25.0 and later
+ + +## Description +How do I focus a blazor input or texbox programmatically? + +## Solution +The Telerik textboxes and inputs offer the `FocusAsync` instance method that lets you focus them with code. + +The example below showcases it for a few of them, but it is available for all inputs (date inputs and pickers, checkboxes, buttons). + +>caption Focus input with code + +````CSHTML +@code{ + async Task FocusTextbox() + { + await TextboxRef.FocusAsync(); + } + + async Task FocusNumericTextbox() + { + await NumericTextboxRef.FocusAsync(); + } + + async Task FocusDropdown() + { + await DropdownRef.FocusAsync(); + } +} + +Focus textbox +Focus numeric textbox +Focus dropdown + + + + + +@code{ + TelerikTextBox TextboxRef { get; set; } + TelerikNumericTextBox NumericTextboxRef { get; set; } + TelerikDropDownList DropdownRef { get; set; } + + string TextoboxValue { get; set; } = "lorem ipsum"; + int NumericTextoboxValue { get; set; } = 123; + string DropdownValue { get; set; } = "one"; + List DropdownData { get; set; } = new List() { "one", "two", "three" }; +} +```` + +## Notes +You can still use JavaScript to focus DOM elements by having a proper element reference or selector. The C# method is built on top of that. If you want more specific functionality (like selecting the text as well, a pure JS solution might be simpler). From 282c5eae6c833d654bafee2aa40885f712aef3d0 Mon Sep 17 00:00:00 2001 From: Dimo Dimov Date: Wed, 14 Jul 2021 14:11:24 +0300 Subject: [PATCH 2/2] docs: Improve KB SEO and enhance information --- knowledge-base/inputs-set-focus.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/knowledge-base/inputs-set-focus.md b/knowledge-base/inputs-set-focus.md index 49d034303c..b142c514dd 100644 --- a/knowledge-base/inputs-set-focus.md +++ b/knowledge-base/inputs-set-focus.md @@ -1,8 +1,8 @@ --- -title: Focus input -description: How to focus a blazor input or textbox +title: Focus TextBox Programmatically +description: How to focus a blazor textbox or input programmatically. type: how-to -page_title: Focus input or textbox +page_title: Focus textbox or input programmatically slug: inputs-kb-focus position: tags: @@ -20,14 +20,29 @@ res_type: kb - ## Description -How do I focus a blazor input or texbox programmatically? +How do I focus a Blazor TelerikTextBox or any other input component programmatically? ## Solution -The Telerik textboxes and inputs offer the `FocusAsync` instance method that lets you focus them with code. +The Telerik textboxes and inputs offer a `FocusAsync` method that lets you focus them with code. + +The example below showcases it for a few of them, but it is available for all input components and buttons: -The example below showcases it for a few of them, but it is available for all inputs (date inputs and pickers, checkboxes, buttons). +* AutoComplete +* Button +* ComboBox +* CheckBox +* DateInput +* DatePicker +* DateRangePicker +* DateTimePicker +* Editor +* MaskedTextBox +* MultiSelect +* NumericTextBox +* TextArea +* TextBox +* TimePicker >caption Focus input with code