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:
app.UIFigure.ButtonDownFcn = createCallbackFcn(app, @UIFigureButtonDown, true);
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'
app.UIFigure.Visible = 'on';
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.