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

조회 수: 49 (최근 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?

답변 (2개)

Alamanda Ponappa Poovaya
Alamanda Ponappa 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

Andres Montes
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.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by