Hi team,
I attempted to try this solution but it seems SFtextbox doesn't accept handler event and preventdefault..
https://tinyurl.com/3yce3xnv
<input value="@name" type="text" @onkeydown="@onKeydown" @onkeydown:preventDefault="@isPreventKey" />
@code {
private string name { get; set; }
private bool isPreventKey { get; set; }
private void onKeydown(KeyboardEventArgs args)
{
if(args.Key == "a")
{
this.isPreventKey = true;
}
}
}
I also tried this solution, however it prevent the submit method upon "enter" but it still shows the validation. I want to show the validation error only upon clicking of "save" button,.
CssClass="e-outline e-success"
FloatLabelType="FloatLabelType.Always"
Placeholder="Scan Item Code"
Width="295px"
@onkeydown="KeyDownHandlerItemCodeAsync"
@bind-Value="@(ADdetailEdit.ItemCode)"
Focus="@OnFocusItemCode">
<button type="submit" @onclick="ShouldISubmit">Savebutton>
@Code{
public bool shouldsubmit { get; set; }
public bool entersubmit { get; set; }
public void InvalidSubmit()
{
if (shouldsubmit)
{
toastService.ShowError("Adjustment was not applied. Check for valid entries."); //toast
}
}
private void HandleValidSubmit()
{
if (shouldsubmit) {
Console.WriteLine("OnValidSubmit");
}
}
public void PreventSubmit(KeyboardEventArgs ev)
{
if (ev.Key == "Enter")
entersubmit = true;
}
public void ShouldISubmit()
{
if (entersubmit)
shouldsubmit = false;
else
shouldsubmit = true;
entersubmit = false;
}
}
here is the model
public partial class InventoryAdjustmentDetailEdit
{
[required]
public string itemcode { get; set; }
}
Best Regards,
Tyrone