How to clear default text in an EditField UI component in App Designer when user clicks it?

18 views (last 30 days)
I have an EditField component in an app I'm making, using App Designer. I've searched everything I can think of, but it seems a lot of the suggestions no longer work. I'm rusing R2019a. I've tried the "start disabled trick" but the ButtonDownFcn for the UIFigure doesn't fire when I click on the field. I've tried just making a callback function that responds to app.EditField.ButtonDownFcn in the UI figure's startupFcn callback, but that just throws an error.
Here's my code for trying the "disable on startup" trick:
%auto generated code that is uneditable
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
% I tried copying the syntax of this but for app.EditField.ButtonDownFcn in the startupFcn callback for the figure and making
% my own custom callback function in place of @UIFigureButtonDown, but that resulted in an error.
app.UIFigure.ButtonDownFcn = createCallbackFcn(app, @UIFigureButtonDown, true);
% Create BookSearchEditField
app.EditField = uieditfield(app.FindMyComicUIFigure, 'text');
app.EditField.FontColor = [0.8 0.8 0.8];
app.EditField.Enable = 'off';
app.EditField.Position = [49 387 239 22];
app.EditField.Value = 'Enter item here'
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
%My code I wrote in the UI figure button down callback
function UIFigureButtonDown(app, event)
mousePos = get(event.Source, 'CurrentPoint');
if mousePos>=app.BookSearchEditField.Position(1) && mousePos>=app.BookSearchEditField.Position(2) && mousePos<=(app.BookSearchEditField.Position(1)+app.BookSearchEditField.Position(3)) && mousePos<=(app.BookSearchEditField.Position(2)+app.BookSearchEditField.Position(4))
app.EditField.Enable = 'on';
app.EditField.Value = '';
app.EditField.FontColor = [0 0 0];
My logic here was to listen for a mouse click event within the figure, and then look to see where the mouse was when the event was triggered and compare it with the location and area of the edit field. However, the callback doesn't trigger when my mouse is over the edit field (and click in the field itself). It only triggers if I click within the figure but not if I'm over a specific component.
I'm trying to make it so the prompt is the default text, and then it disappears when the user clicks it to type their input.
I feel like there has to be some sort of usable event, whether a mouse click or the gaining or changing of focus on a ui component, that can allow for this.
Thank you for any help or advice.

Answers (1)

Vimal Rathod
Vimal Rathod on 23 Jul 2019
I understand that you require a placeholder feature to put as a default text in the startup of app which disappears when you click on the text box. The placeholder feature is not available in the present versions.
The ButtonDownFcn is UIFigure specific and doesn’t trigger through another component like you mentioned because the area is over-written by the component(UIEditField) and cannot be accessible by the underlying component(UIFigure).
Richard Genik
Richard Genik on 5 Oct 2020
I'm trying to accomplish the exact functionality -- have there been any updates to App Designer to allow placeholder text to appear in Edit boxes?

Sign in to comment.


Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!