App Designer: Triggering ValueChanged callback for text Edit Field with Default Value

62 views (last 30 days)
In the attached simple App Designer app enter_name.mlapp, you enter your name in the top field, and then after pressing Enter, the name appears in the bottom field.
I am populating the top field with a default name, 'David.' Now if you click into the top field, and just press Enter (with the intention of accepting the default name), the InputValueChanged callback is never called and the name David does not appear in the bottom field. You need to add or edit something in the top field before the InputValueChanged callback will be triggered.
Is there any way to change or override this behavior?

Answers (1)

Alamanda Ponappa Poovaya
Alamanda Ponappa Poovaya on 6 Sep 2021
I understand you want to show the default value in the start by pressing enter. The issue is that text fields only have 2 call back options, and both only work if value is changed. There is a possible work around. You can add a keyboard event listener to the UIFigure of the app to react to pressing enter. However this will only work if your top edit text is not in focus, so press enter before clicking on the top text, or take the top text out of focus by clicking anywhere else on the app. The code for the keyboard callback is below
function UIFigureKeyPress(app, event)
key = event.Key;
if key == "return"
% Retrive data
name = app.Input.Value;
% Clear it
app.Input.Value = '';
% Log it
app.Output.Value = name;


Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!