Form setFocus()


I’ve dug around and don’t seem to find a handy solution for this. In 5.x there were functions for setting the focus in a form. How does one set the focus in 6.x?

There was also a function to set the focus on the first editable field in the form. I can probably figure out how to duplicate that behavior if I can set the focus at all, but perhaps there’s an easy way to do this already?


I figured out that as long as you set the id property of the control, you can use document.getElementById(“control_id”).focus() to set the focus on a specific field.

I see that the form controls are stored in form.config.rows, so you could theoretically loop through that array to find the first visible control. Something like this:

var firstvisible;
for (var i=0;i<form.config.rows.length;i++){
    var ctrl = form.config.rows[i];
    if (typeof ctrl.hidden === "undefined" || ctrl.hidden === false){
        firstvisible = ctrl.id;

Is there a better/easier way to do this?


You may use your chosen solution for now.
I understand your problem. We’ll add the kind of “focus()” method in one of the future dhtmlxForm updates.
Thank you for your report.