Initial value in uihtml + Javascript implementation of text input

Since I got extremely helpful input on a previous question on this same general theme:
I thought I'd turn to you amazing people again.
In the attached .mlapp and .html files, the app simply asks for input in the top box and echos whatever is entered there in the bottom box. Nice and simple.
What I'd like to do is have an initial value appear in this box, sent over from MATLAB. In this code, I am trying two things out:
1) I try entering one string in the startupFcn, line 17
2) I try entering another string in the initial definition of the uihtml widget, line 53.
Neither string appears when the app is run.
When input is received in the app and is recorded in the bottom box, it simply echos to the screen (when run inside MATLAB) the state of the "event" variable. That shows that app.HTML.Data was correctly set in startupFcn, line 17, but that value is not being sent over to the Javascript or not triggering the DataChanged listener in the Javascript code.
The process of updating the text that appears in the upper box, using app.HTML.Data = ... works just fine elsewhere in the MATLAB code, like in line 29.
So it seems that a listener, either on the MATLAB or on the Javascript side, is not up and running when the app's startupFcn executes. Is there a way to set an initial value in the uihtml text edit box in the startupFcn, or at least before the app has started and is waiting for user input?

댓글 수: 3

Hey David! I am using Matlab 2021a, and when I run your app I can see the 'startupFcn test!' being displayed on the UIHTML input. If I remove the sartup function I also see the initial value fo the Data property (line 53).
I can't tell you for sure, but it might be that the 'setup' function in your .html file has not yet been executed when you set the Data property. You can check this matlab article that says that:
The setup function is called when one of these events happens:
  • The HTML UI component is created in the figure and the content has fully loaded.
Have you tried using 'drawnow' commands before setting the Data property in the startup function? That will force the html content to load
function startupFcn(app)
drawnow;
app.HTML.Data = 'startupFcn test!';
end
David Aronstein
David Aronstein 2021년 10월 13일
편집: David Aronstein 2021년 10월 13일
Thank you, Antonio! Adding the drawnow command does make the "startupFcn test!" text to appear in the top text box, in MATLAB 2020a. Fantastic!
You helped so much with my last question, too... I think I should just direct my questions straight to you in the future... :)
On a mundane note, your reply shows up as a "Comment" instead of an "Answer" and I'm not sure how to mark it as the accepted answer? I will certainly give you "credit" for it if I am able.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Scripts에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2021년 10월 11일

편집:

2021년 10월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by