How to create an empty edit field (numeric) in app designer

22 ビュー (過去 30 日間)
John Cadigan
John Cadigan 2019 年 4 月 5 日
回答済み: Juan Andrés Martin 2023 年 8 月 3 日
I am writing an app that has a user enter a quantity in a numeric Edit Field. The field starts off with a default value of 0 so that the user has to delete the 0 and then enter the number. Is there a way to get the default to be empty rather than a 0?
  1 件のコメント
Marc Youcef
Marc Youcef 2019 年 8 月 13 日
I was searching for same request but apprently there is no way to do that using uinumericeditfield as this edit field forces you to have at list a numeric value. Which is a pain when you do not want the user to necessarly enter something in, you get a 0 value instead of empty field...

サインインしてコメントする。

回答 (4 件)

Gonzalo Montero
Gonzalo Montero 2019 年 12 月 12 日
I'm looking for the same feature, it's a pity that is not possible!

sing
sing 2022 年 4 月 20 日
A workoaround solution is to set the color of the text equal to the box's background (typically white).
E.g.:
app.editfield.FontColor=[1 1 1]
  2 件のコメント
Chris
Chris 2022 年 4 月 20 日
Using a string editField then and a ValueChangingFcn call back to set the color back to black? Sounds like a good option.
sing
sing 2022 年 4 月 20 日
編集済み: sing 2022 年 4 月 20 日
Exactly, then when you need to write a value in the numeric box that you want to be visibile you just need to set app.editfield.FontColor=[0 0 0] and then you can assign the value you like to it, app.editfield.Value=yourvalue

サインインしてコメントする。


Chris
Chris 2019 年 8 月 13 日
Can you make the input a text field and reject anything that does not convert to a number?
  2 件のコメント
Marc Youcef
Marc Youcef 2019 年 8 月 13 日
Yes, this is the only solution I thought about. Unfortunately in my case I was trying to take advantage of the 'uinumericeditfield' functionnality which is doing exactly this for you and wanted to simply add an 'empty by default' option.
frankenberry
frankenberry 2020 年 5 月 21 日
I was able to use a blank text area to accept only numbers. I'm not sure how good it is or if it helps you at all. The only problem I have with this is that if the field is blank, it should also give an error. That is, I get an error if the value is not a number and the error box pops up or if it is blank, I should get an error. I need to code that part yet. I tested this and it works in my app. I don't get an error when numbers are entered.
% Value changed function: NEQO_A4_pistol
function NEQO_A4_pistolValueChanged(app, event)
value = app.NEQO_A4_pistol.Value;
string(value);
if isempty(str2num(value))
app.NEQO_A4_pistol.Value,value;'0';
uialert(app.UIFigure, {'You need to enter a number','Click OK and enter a number value'}, 'Error', 'Icon', 'Error');
app.NEQO_A4_pistol.Value = '';
elseif ~isempty(str2num(value))
app.NEQO_A4_pistol.Value,value;'0', '1', '2', '3', '4', '5', '6', '7', '8', '9';
%uialert(app.UIFigure, {'You entered a number! WOOHOO!'}, 'Info', 'Icon', 'info');
end
end

サインインしてコメントする。


Juan Andrés Martin
Juan Andrés Martin 2023 年 8 月 3 日

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by