필터 지우기
필터 지우기

Matlab ignoring uihtml autofocus attribute in 2021b

조회 수: 1 (최근 30일)
Joel Lau
Joel Lau 2021년 11월 5일
답변: Antonio Hortal 2021년 11월 8일
We have several Matlab apps that use uihtml components. In 2020b, we used the autofocus HTML attribute to control which app component was selected when the app started (and then controlled the stack order using Reorder as introduced in 2020b). We're transitioning from 2020b to 2021b and a common complaint from our users is that the autofocus attribute appears to be ignored now.
The attached zip file includes an app & html file with a simple example. When the app is opened in 2020b, the username field is selected and the user can enter text immediately. When the app is opened in 2021b, the user has to click the edit field or press the tab key before they're able to enter text.
Is there a workaround for this behavior change or a more elegant way to control an app's focus on startup?

채택된 답변

Antonio Hortal
Antonio Hortal 2021년 11월 8일
One thing that you could do is to have an HTML event that requests focus on the input element whenever the startup function of the app finishes:
function startupFcn(app)
app.HTML.HTMLSource = 'usernameInput.html';
% Maybe you need a drawnow() here, but I have tried without it and it
% worked
app.HTML.Data.FocusOnInput = true;
end
In your .html file you will just need to add a listener in the setup function:
htmlComponent.addEventListener("DataChanged", function(evt) {
if (evt.Data.FocusOnInput){
document.getElementById("usernameInput").focus();
}
})
I don't have matlab 2021b (only 2021a, and it behaves the same as 2020b), but I have tried running my code without the "autofocus" property in the <input> and it worked. Hopefully it also works in the 2021b! Let me know how it goes :)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by