How to modified "edit fied (text)" from app design

조회 수: 1 (최근 30일)
Palma Errico
Palma Errico 2020년 9월 7일
댓글: Palma Errico 2020년 9월 13일
I need that the ''edit field text'', in my app, is limited to a maximum of 20 characters and a pop-up error message that appears if you enter more than 20 characters.
How could i do?

채택된 답변

Mario Malic
Mario Malic 2020년 9월 7일
편집: Mario Malic 2020년 9월 12일
Add this to the value changed callback, adjust the name of your field.
if length(app.EditField.Value) <= 20
Text = app.EditField.Value; % If you will use the text
else
% app.EditField.Value = ''; % you can clear out the text if needed
f = uifigure;
Error_Msg = "Error message"
Error_Title = "Error title";
uialert(f, Error_Msg, Error_Title,'CloseFcn',@(h,e) close(f));
end
It takes a little bit of time to display the message, if that is an issue, then you can use tooltip, I have no example with tooltip.
Above portion of code creates a new figure which takes a bit of time. Here's a better solution with help from Adam.
if length(app.EditField.Value) <= 20
Text = app.EditField.Value; % If you will use the text
else
% app.EditField.Value = ''; % you can clear out the text if needed
f = app.UIFigure; % f is handle to your app UI figure
Error_Msg = "Error message"
Error_Title = "Error title";
uialert(f, Error_Msg, Error_Title);
end
  댓글 수: 2
Palma Errico
Palma Errico 2020년 9월 8일
It was really useful! Thank you.
Palma Errico
Palma Errico 2020년 9월 13일
@Mario Malic yes I had already made this change to my app, because I realized that the error message was slow. Your help on setting up the code was crucial though. Thanks again!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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