App Designer: Triggering ValueChanged callback for text Edit Field with Default Value
44 ビュー (過去 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 Apps Using App Designer についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!