App Designer: Triggering ValueChanged callback for text Edit Field with Default Value
37 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Drishan Poovaya
2021-9-6
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 个评论
Vitek Stepien
2022-9-16
Can you add the listener in a way that it ONLY listens when the EditField is in Focus?
Andres Montes
2023-3-23
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!