App Designer: Triggering ValueChanged callback for text Edit Field with Default Value
39 views (last 30 days)
Show older comments
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?
0 Comments
Answers (2)
Drishan 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;
end
end
1 Comment
Vitek Stepien
on 16 Sep 2022
Can you add the listener in a way that it ONLY listens when the EditField is in Focus?
Andres Montes
on 23 Mar 2023
Hi, I had the same issue but I think I made it work.
Try creating a UIFigureWindowKeyRelease callback. Also delete the InputValueChanged callback
function UIFigureWindowKeyRelease(app, event)
key = event.Key;
switch key
case 'return'
% Retrive data
name = app.Input.Value;
% Clear it
app.Input.Value = '';
% Log it
app.Output.Value = name;
end
end
Hope it works ;), first time amswering something in MATLAB Answers, kind of excited hahaha.
0 Comments
See Also
Categories
Find more on Develop uifigure-Based Apps 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!