Open and set the focus on a specific element via URL

Hi

Is there a way to set the focus / cursor directly on a specific field when opening a form via a URL?

Mike

Dear @bigmad,
Sure, we have an example on how to populate fields from a link - Populate form with data from different sources with JavaScript (public forms) — Public web forms

Same can be done with the focus, though the following code will only work for some fields which have an input to focus on:
window.$ = $;

//https://mydomain.plumsail.io/432d-9618-b81b32a4016b5?focus=Title
fd.rendered(function(){
    var queryString = window.location.search;
    var urlParams = new URLSearchParams(queryString);
    $(fd.field(urlParams.get('focus')).$el).find('input').focus();
    $(fd.field(urlParams.get('focus')).$el).find('input').scrollIntoView();
});

Dear Nikita, Thanks for your answer. I need the function for guiding my users to find the right field in a form. But, unfortunately the field is empty at the beginning.
If I understand right, then your code works by finding a specific input.

Mike

Dear @bigmad,
It works by finding the input of specific field, specified in the URL. Some fields have input, others do not, so it wouldn't work for all field types, but it works well:

Let me know the field types you're working with, we can help adjust the code.

This code above also looks for specific field in the URL params, but if you know what the field is and don't need to get it from URL, you can simply place field name in the code:

fd.rendered(function(){
    //focus and move to Title field
    $(fd.field('Title').find('input').focus();
    $(fd.field('Title').$el).find('input').scrollIntoView();
});