I am testing with a Blazor WASM Standalone app that uses Telerik UI for Blazor. I have a sample page with a button on click of which a predefined dialog (for example, alert) is shown. If you make some change on the page and hot reload is enabled, the button click no longer opens the predefined dialog. The dialog is shown only if I navigate to a different page.
When a Dialog is shown from a modal Window, the Dialog appears behind the Window on second opening.
Here is a test page with a workaround:
@inject IJSRuntime js
<TelerikButton OnClick="@( () => WindowVisible = true )">Show Window</TelerikButton>
<TelerikWindow @bind-Visible="@WindowVisible"
Modal="true">
<WindowActions>
<WindowAction Name="Minimize" />
<WindowAction Name="Close" />
</WindowActions>
<WindowTitle>
Window Title
</WindowTitle>
<WindowContent>
<p>Window Content</p>
<TelerikButton OnClick="@OnShowDialogButtonClick">Show Dialog</TelerikButton>
</WindowContent>
</TelerikWindow>
<TelerikDialog @bind-Visible="@DialogVisible"
Width="300px"
Class="dialog-on-window">
<DialogTitle>
Dialog Title
</DialogTitle>
<DialogContent>
<p>Dialog Content</p>
</DialogContent>
<DialogButtons>
<TelerikButton OnClick="@( () => OnDialogButtonClick(true) )">OK</TelerikButton>
</DialogButtons>
</TelerikDialog>
<script suppress-error="BL9992">
function bringDialogToTop() {
var dialogWrapper = document.querySelector(".dialog-on-window").closest(".k-dialog-wrapper");
if (dialogWrapper) {
dialogWrapper.style.zIndex = parseInt(dialogWrapper.style.zIndex) + 2;
}
}
</script>
@code {
private bool WindowVisible { get; set; }
private bool DialogVisible { get; set; }
private bool ShouldFocusDialog { get; set; }
private void OnShowDialogButtonClick()
{
DialogVisible = true;
ShouldFocusDialog = true;
}
private void OnDialogButtonClick(bool result)
{
DialogVisible = false;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (ShouldFocusDialog)
{
ShouldFocusDialog = false;
await Task.Delay(1);
await js.InvokeVoidAsync("bringDialogToTop");
}
await base.OnAfterRenderAsync(firstRender);
}
}
Hello I want to close a TelerikDialog using Esc key and this does not work sometimes. Run this REPL snippet please https://blazorrepl.telerik.com/cnYrwUYq54FZ70xP17. Click into dialog title for instance and press Esc key. Nothing happens.
Very thanks.
Miroslav
Hello,
I am using DialogFactory in a Blazor server app with PreRendering disabled.
It appears to cause more than expected OnParametersSet calls - its firing 2-6 times per page opening. Without DialogFactory it fires only once.
The issue can be reproduced when clicking on a button that opens a predefined Dialog, then making some changes on the page and hot reloading. In this scenario, I get the following error:
Microsoft.JSInterop.JSException: Cannot read properties of null (reading 'addEventListener') TypeError: Cannot read properties of null (reading 'addEventListener')
There is a bug where DialogFactory is not resetting custom button text. In this example, if you click Show Prompt, the buttons are OK/CANCEL, then click Show Prompt with Title, Default Input Text and Custom Buttons, the buttons show READY/REJECT, clicking Show Prompt a second time will show the button text as READY/REJECT.
<AdminEdit>
This feature request would be used to monitor the requests for a full-fledged Dialog component. It will be defined in the Markup and will provide options to customize the Header and Content and will expose Action buttons.
</AdminEdit>
I want to fill the textbox of the prompt with predefined text, can we have that same behavior like in kendo https://docs.telerik.com/kendo-ui/api/javascript/kendo/methods/prompt?
---------
ADMIN EDIT
Here is a workaround
@inject IJSRuntime _js
<TelerikButton OnClick="@PromptWithText">Workaround</TelerikButton>
@code{
[CascadingParameter]
public DialogFactory Dialogs { get; set; }
async Task PromptWithText()
{
// the workaround - invoke a script that will set the input value with a delay
await _js.InvokeVoidAsync("setPromptDefaultText", "predefined prompt value");
// do the prompts as usual
string prompt = await Dialogs.PromptAsync("Enter something");
Console.WriteLine(prompt);
}
}
@* move this script to a proper location, this is a hack
to put in the blazor component so the workaround is easy to copy and run *@
<script suppress-error="BL9992">
function setPromptDefaultText(defText) {
setTimeout(function(){
var promptInput = document.querySelector(".k-prompt-container .k-textbox .k-input-inner");
if(promptInput) {
promptInput.value = defText;
promptInput.dispatchEvent(new Event('input', {bubbles: true} ));
}
}, 50); // a timeout so the prompt can render first
}
</script>
---------
Hi!
Please check the example:
https://blazorrepl.telerik.com/mdaIltlV32cFnMiX42
Why is predefined dialog put in to the back? This happens when i show predefined dialog from OnInitialize or AfterRendered method.
Regards, BoĊĦtjan
Pressing Espace in a focused SearchBox throws an "Error: System.ObjectDisposedException: The CancellationTokenSource has been disposed." exception.
<AdminEdit>
A workaround that will solve the issue until the fix is released.
<TelerikDialog @bind-Visible="@Visible"
Title="@Title">
<DialogContent>
<TelerikGrid Data=@GridData Pageable="true" Height="400px" Width="700px">
<GridToolBar>
<span class="k-toolbar-spacer"></span> @* add this spacer to keep the searchbox on the right *@
<div onkeydown="event.stopPropagation()">
<GridSearchBox />
</div>
</GridToolBar>
<GridColumns>
<GridColumn Field="@(nameof(Employee.EmployeeId))" />
<GridColumn Field=@nameof(Employee.Name) />
<GridColumn Field=@nameof(Employee.Team) Title="Team" />
<GridColumn Field=@nameof(Employee.IsOnLeave) Title="On Vacation" />
</GridColumns>
</TelerikGrid>
</DialogContent>
</TelerikDialog>
@code {
private bool Visible { get; set; } = true;
private string Title { get; set; } = "Software Update";
public List<Employee> GridData { get; set; }
protected override void OnInitialized()
{
GridData = new List<Employee>();
var rand = new Random();
for (int i = 0; i < 15; i++)
{
GridData.Add(new Employee()
{
EmployeeId = i,
Name = "Employee " + i.ToString(),
Team = "Team " + i % 3,
IsOnLeave = i % 2 == 0
});
}
}
public class Employee
{
public int EmployeeId { get; set; }
public string Name { get; set; }
public string Team { get; set; }
public bool IsOnLeave { get; set; }
}
}
</AdminEdit>
Hello,
Please add support for MarkupString in the predefined awaitable dialogs. This will allow us to add new lines and other simple rich content, without the need to resort to the full-blown Dialog component.
Currently using VisibleChanged event, I can tell when a dialog is closed. However, if you have a component inside the dialog and trying to reference that component before the dialog is fully rendered you get a null reference exception.
What I am proposing is adding a new event or extending VisibleChanged so that we know when the dialog has been initialized.