I really need something to catch the edits in an InputField. Right now there is OnValidateInput but that is not very useful. It seems to miss a parameter.
public char ValidateTheInput(string oldValue, int i, char c)
oldValue is the inputField value before the new char is processed, which is correct because we have to approve, deny or alter it.
i seems to be the begin of the selected region in the edit text
c is the typed char
but where is the end of the selected region? This way I cannot reconstruct the value after processing the char unless I wait a frame and query the InputField. But that produces lousy code.
OnValidateInput is also not called when delete or backspace is pressed
The alternative is OnSubmit, which is only called upon the submit action. Simply clicking a button or selecting another InputField after typing the text is not considered a submit.
So right now there is no way for me to know for sure if the value has changed or not
Can we have something like this please? Or is there maybe another way?
Neither of these solutions will work unfortunately.
The thread mentioned uses OnValidateInput and OnSubmit, which I use as well, but dont do the job. These cannot be used the simulate an OnChange event, because OnValidateInput is only called when an actual character is typed (not when you use backspace for instance) and OnSubmit is only called on submit.
The use case here is a hierarchy with all sorts of data that is displayed and can be changed. Like so:
email: [inputfield for email ]
[+ some other inputfields]
When the user edits the email address field, a password is required for authentication. So a password field is added dynamically and it becomes:
email: [inputfield for email ]
password: [inputfield for last name ]
When the password field is entered and the value is sufficiently long, A Save button is dynamically added.
Without the OnChange event I am forced to always have the password field on screen and always have the Save changes field on screen.
Sorry to keep bugging about it, but the quote you mention applies to the fact that OnSubmit was not present in the inspector. Although the word “This” is not 100% clear about that.
What I need/want/crave is an OnChanged event.
To be absolutely clear about what I mean:
An OnChanged event is triggered AFTER the inputfield value is changed by whatever input that has changed it. Not BEFORE the change and not just because of using the Enter key or ABCD…0123…, but also because of the use of Ctrl-X, Ctrl-V, delete, backspace, and whatever user action you can think of.
I can solve it by using
function Update() {
if(storedInputFieldValue != inputField.value) { … DoSomething(); }
}
But that only works on MonoBehaviours, is called every frame and really is not worthy of this beautiful new UI + EventSystem which I absolutely LOVE!
This is just completely wrong. Read it again. I said that I need the same functionality as you do and that onSubmit doesn’t do the job. I did not ask for onSubmit to be included in the inspector as you implied, I’d rather want an onValueChange and have that included in the inspector as well. A temporary solution which polls the value based on Input Actions Per Second (usually 10 instead of every frame) has also been posted in the thread by bocs.
It’s at least 4 of us I agree that InputField really should have OnValueChange as an event that I can register for (also in the editor). This should fire on any change.