Opened

onfocus="this.select();" does not seem to work in newest version in NumericEdit

mdwyer commented edited

In the older version 0.9.0.3 on a NumericEdit, I was able to user onfocus="this.select();"
This is throwing an error in the 0.9.4.1.

The goal is when the user enters the input that the current text gets selected so when they type it replaces what is there by default.

This worked in 0.9.0.3:
<<NumericEdit TValue="decimal" Decimals="2" Value="@(Convert.ToDecimal(val))" ValueChanged="@(v => ((CellEditContext)context).CellValue = v)" Size="Size.ExtraSmall" Margin="Margin.Is0" Padding="Padding.Is0" onfocus="this.select();" />>

In 9.4.1 I get this error:
System.InvalidOperationException: Unable to set property 'onfocus' on object of type 'Blazorise.Bootstrap.NumericEdit1[[System.Double, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. The error was: Unable to cast object of type 'System.String' to type 'Microsoft.AspNetCore.Components.EventCallback1[Microsoft.AspNetCore.Components.Web.FocusEventArgs]'.
---> System.InvalidCastException: Unable to cast object of type 'System.String' to type 'Microsoft.AspNetCore.Components.EventCallback1[Microsoft.AspNetCore.Components.Web.FocusEventArgs]'. at Microsoft.AspNetCore.Components.Reflection.PropertySetter.CallPropertySetter[TTarget,TValue](Action2 setter, Object target, Object value)
at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.

mladenmacanovic commented

The reason why error happens is that we now have a dedicated event handler that you can use instead. It is named OnFocus. You just need to replace attributes.

mladenmacanovic commented

I have re-read your message and I can now understand what you meant. When onfocus="this.select();" is used without the @ prefix it will execute the code as a JavaScript in this case. This is Blazor native support but since we already have implement onfocus, in Blazorise it will not work.

We would need to add new API into Blazorise NumericEdit to be able to support this. I suggest to add .Select() method that could be used along with existing OnFocus event.

Since it is introducing new API it is not possible to add as part of 0.9.4, but I will schedule it for 0.9.5 and it will be done as part of the first preview.

mladenmacanovic commented
David-Moreira commented

Also you should still be able to bind to the Blazorise OnFocus event and still javascript interop the select function with some minor changes, right?

Want to comment on this issue? Log in and write your comment.
Asignee
No assignee
Labels
No Labels