|
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Inputs
@using System.ComponentModel.DataAnnotations;
<div class="row">
<div style="width:100%;margin:20px;">
<EditForm EditContext="@editContext">
<DataAnnotationsValidator />
<div class="form-group">
<SfTooltip @ref="tooltipObj" OpensOn="custom" >
<SfTextBox Placeholder="Test Property" FloatLabelType='@FloatLabelType.Always' @bind-Value="model.TestProperty" CssClass="@cssClass" Blur="TestPropertyBlurEvent"></SfTextBox>
<TooltipTemplates>
<Content>
<ValidationMessage For="@(() => model.TestProperty)"></ValidationMessage>
</Content>
</TooltipTemplates>
</SfTooltip>
</div>
<SfButton IsPrimary="true" HtmlAttributes="@(new Dictionary<string, object> { { "type", "submit" } })">Save</SfButton>
</EditForm>
</div>
</div>
@code{
SfTooltip tooltipObj;
private Test model;
private EditContext editContext;
private string temp { get; set; }
private double tipx { get; set; }
private double tipy { get; set; }
private string cssClass { get; set; }
protected override void OnInitialized()
{
model = new Test();
editContext = new EditContext(model);
}
public class Test
{
[Required]
public string TestProperty { get; set; }
}
public void TestPropertyBlurEvent(FocusOutEventArgs args)
{
if (!editContext.Validate())
{
cssClass = "e-error";
tooltipObj.Open();
}
else
{
cssClass = "e-success";
tooltipObj.Close();
}
}
} |
@using Syncfusion.Blazor.Inputs @using Syncfusion.Blazor.Popups <SfTooltip @ref="@tooltip" Target="@("#" + ID)" OpensOn="Custom"> <TooltipTemplates> <Content> @ValidationTemplate </Content> </TooltipTemplates> <SfTextBox @ref="@textbox" ID="@ID" Placeholder="@Placeholder" @bind-Value="@Value" Readonly="@Readonly" FloatLabelType='@FloatLabelType.Auto' CssClass="e-error" @onmouseover="OnMouseOver" @onmouseout="OnMouseOut"></SfTextBox> </SfTooltip> @code { SfTooltip tooltip; SfTextBox textbox; [Parameter] public string ID { get; set; } [Parameter] public string Placeholder { get; set; } [Parameter] public bool Readonly { get; set; } [Parameter] public RenderFragment ValidationTemplate { get; set; } [Parameter] public EditContext EditContext { get; set; } private string _value; [Parameter] public string Value { get { return _value; } set { if (_value != value) { ValueChanged.InvokeAsync(value); } _value = value; } } [Parameter] public EventCallback<string> ValueChanged { get; set; } void OnMouseOver(MouseEventArgs args) { EditContext.Validate(); if (textbox.CssClass == "e-error") { tooltip.Open(); } } void OnMouseOut(MouseEventArgs args) { tooltip.Close(); } } |
And called it liked this :
<KTextBox ID="adresse" Placeholder="Adresse" @bind-Value="@Adresse.Adresse1" Readonly="@Parameters.Wizard.IsReadOnly" EditContext="editContextHeader"> <ValidationTemplate> <ValidationMessage For="@(() => Adresse.Adresse1)" /> </ValidationTemplate> </KTextBox> |
The tooltip never opens.
Thx.
|
@page "/"
@using Syncfusion.Blazor.Buttons
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Inputs
@using System.ComponentModel.DataAnnotations;
@inject IJSRuntime JsRuntime
@using Newtonsoft.Json
<div class="row">
<div style="width:100%;margin:20px;">
<EditForm EditContext="@editContext">
<DataAnnotationsValidator />
<div class="form-group">
<SfTooltip @ref="tooltipObj" ID="tooltip" OpensOn="Custom">
<SfTextBox ID="textbox1" @bind-Value="model.TestProperty" Focus="focused" Blur="@(e => TestPropertyBlurEvent(e, "textbox1"))"></SfTextBox>
<br>
<br>
<br>
<SfTextBox ID="textbox2" @bind-Value="model.TestProperty" Focus="focused" Blur="@(e => TestPropertyBlurEvent(e, "textbox2"))"></SfTextBox>
<br>
<br>
<br>
<SfTextBox ID="textbox3" @bind-Value="model.TestProperty" Focus="focused" Blur="@(e => TestPropertyBlurEvent(e, "textbox3"))"></SfTextBox>
<Content>
<ValidationMessage For="@(() => model.TestProperty)"></ValidationMessage>
</Content>
</TooltipTemplates>
</SfTooltip>
</div>
<SfButton IsPrimary="true" HtmlAttributes="@(new Dictionary<string, object> { { "type", "submit" } })">Save</SfButton>
</EditForm>
</div>
</div>
@code{
[Inject]
public IJSRuntime JSRuntime { get; set; }
SfTooltip tooltipObj;
private Test model;
private EditContext editContext;
protected override void OnInitialized()
{
model = new Test();
editContext = new EditContext(model);
}
public class Test
{
[Required]
public string TestProperty { get; set; }
}
public void focused(FocusInEventArgs args)
{
tooltipObj.Close();
}
public async Task TestPropertyBlurEvent(FocusOutEventArgs args, string ID)
{
if (!editContext.Validate())
{
// Pass the id of the focused out of textbox to the client side to open the tooltip targetted to that textbox.
var value1 = await JSRuntime.InvokeAsync<string>("AddPanel", ID);
}
else
{
tooltipObj.Close();
}
}
} |
|
<script>
function AddPanel(args) {
document.getElementById("tooltip").ej2_instances[0].open(document.getElementById(args));
}
</script> |
function hasContent(id) { var message = document.querySelector("#" + id + "_content > .e-tip-content > .validation-message"); return (message !== null); } |
Razor
void OnOpen(TooltipEventArgs args) { var jsRuntimeSync = (IJSInProcessRuntime)jsRuntime; var hasMessage = jsRuntimeSync.Invoke<bool>("kairos.layout.hasContent", tooltip.ID); args.Cancel = !hasMessage; } |
Do you think, it is a good way to achieve my requirement ?