I have a text field from which data needs to be saved every time I edit the text field.
What is the best approach to do this( which event should be triggered), so that the number of times the data is saved can be minimized.
I don’t want to have an “Enter” key to be pressed to save data
The onBlur event documentation says, ‘Fired when the element loses focus. This usually happens when the user focuses something else’ so this will be triggered of the user clicks outside the text field or tabs out of the field.
If you’re going to do this then beware of creating user confusion about whether or not the value has been stored. I would consider a subtle color or background change if the value has changed and reset to normal when saved. I would also save when Enter was pressed as that’s a reasonable user expectation.
Be aware that the edit will be lost if the user navigates away from the page.
You should be using an onChange script. Right-click the text property of the Text Field component and select “Add Change Script”. Perform your “save” logic here, using currentValue.value. This does not require the user to press Enter; the change script will execute any time the user modifies the value and “leaves”/“submits” the changes.
This is an odd thing to ask, as the data would be saved exactly as many times as the user edits the field. There’s no minimizing to be done if your condition is save-on-change.