Autofocus for Select in Custom HTML Prompt Action (v9.0.2)

Could anyone tell me why autofocus doesn't work for a dropdown in a custom HTML prompt? It works for other input types (like textarea, for instance). The simple example below does not autofocus in KM, but the same HTML autofocuses in browsers. It turns out that this is actually kind of a big deal in my real uses, so I'm hoping there's a solution.

Why No Autofocus? Macro (v9.0.2)

Why No Autofocus?.kmmacros (2.2 KB)

I don't know, but I found an HTML syntax validator at The W3C Markup Validation Service and I plugged your HTML in there and it gave me one error and one warning.

I went back to the site to copy and paste the exact error for you. Now the site isn't working. But I think I remember the error indicating that you were missing a Title. And I can see that's probably the case because you have no text between title and /title.

This isn't a solution for you. I'm not experienced enough with HTML to answer this. It's just an idea.

EDIT: sorry for quoting only one word of your post. That was an error.

Thanks. I'm aware of the lack of title, but that has nothing to do with the Select block, which works just as I expect it to in browsers, but not in KM.

Ok so I spent a half hour googling this and found this article which shows you how to inspect the elements in the custom form created by KM. If you want to validate if the form has the correct HTML, try this approach.

Here's an article on the internet about how to write HTML to set autofocus to a selection box.

I know you said your code works in browsers. I'm not arguing that. I'm just saying there might be another way to get it to work, following the example on the above page.

I appreciate your effort, but I don't think it's an issue with the code. I've had to abandon KM and find a solution elsewhere.

I can confirm this behavior, running Keyboard Maestro 9.0.2 on macOS 10.14.6 (Mojave).

I tested your macro, as well as several other KM Macros with HTML Prompts, and they all exhibit the same behavior -- focus is NOT set to SELECT element when either the autofocus or selected attributes are provided.

I also confirm that the select element does have focus when your HTML is displayed in Safari and Brave Browser.

@peternlewis, so I have to conclude this is a KM bug.

@thoffman666, as a workaround, you can just add a KM Action of Type Keystroke TAB after the HTML Prompt. However, you do have to set the HTML Prompt Action to run asynchronously (in the Gear menu).

Yes, I’ve used that workaround in other macros, but it’s not an acceptable workaround, because it presents other problems related to processing of forms. It’s much better to have an HTML prompt that works as HTML should.

Autofocus only works in Keyboard Maestro in input or textarea fields.

I will add support for select fields for a future version (probably 9.1).

1 Like