-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Firing onchange before painting on input #5544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
As far as I'm aware, Blazor only has support for the The second example, I'm not quite sure I'm understanding what is required. You're setting the 'value' attribute of the html to "Foo", which happens when the page is loaded. After that, if the user changes the input, the value attribute will change to that since that's how input elements work. If you don't want users to change the value, then consider not using a input element or use the readonly html attribute. |
Hello @Worble, Thank you! I know the input has a value attribute that contains the initial value, and value property that contains the actual value. The second example is directly related with the first example. If the onchange event is fired before painting the new value in the input, and the event doesn't change the value, the old value must stay in the input like a readonly property. I propose a onchange behavior like ReactJs (https://www.peterbe.com/plog/onchange-in-reactjs) I will read your link about textInput event, maybe it could be what I need. Thank you! |
In Blazor 0.4.0 there are a lot of different events including onkeydown, onkeyup, onkeypress but it is still difficult to implement what @montyclt wants. The biggest problem is the lack of "event is fully handled in my code". Here is a very simple and incomplete example: <input bind="@TestValue" onkeypress="@KeyHandler" /> int TestValue { get; set; }
void KeyHandler(UIKeyboardEventArgs ev)
{
if (ev.Key.CompareTo("+") == 0)
TestValue++;
else if (ev.Key.CompareTo("-") == 0)
TestValue--;
} Now you can press
As you can see at this stage of Blazor development there are a lot things we have to do in JavaScript. @SteveSandersonMS maybe you have some suggestion. Here is our discussion from #803 Is this still unsolvable in Blazor?
|
Try using onblur?
|
Having information about the caret position is a must when creating editor components. Any update on this? Additionally is there any conception for cancellable events. For example I want to cancel the keypress event of an input element. Do I need to use JavaScript interoperability? |
Closing as a duplicate of #5545 The original requirement (text input, into which the all input is forced into uppercase) is handed quite easily using
|
In general, yes. Since this has to be synchronous, you can't use .NET code for that (e.g., because of Razor Components). Our hope is that this is a sufficiently rare case that it's not going to impact productivity much, and if there are scenarios that are common enough, we can come up with suitable helpers for it. |
Hello everyone,
I have an input that I need that the user only writes in upper case.
I tried to do the following:
The result:
The user writes in lowercase and when the user left focus, then the content transform to upper.
I tried too a hardcode value of Name property and left ChangeName method in blank like this:
I expected the original value of input return to "Foo", but when I leave the focus, the changed value stayed in the input.
Is possible make the value of input doesn't change if the value of
value
property doesn't change even if user type letters? (likereadonly
property)Is possible to fire the onchange method before painting the input value to get in the input the value directly transformed while writing instead on lose focus? (like ReactJS)
The text was updated successfully, but these errors were encountered: