How to set focus on input element in form

Hello,

how can I set the focus to a determined input element in a form at run-time?

Best regards

Horst Muerdter
CrossData-Tools

Check
viewtopic.php?f=22&t=16788&p=56077#p56077

Thank Stanislav,

this is true before executing dhx.ui (…). There you can set focus and it works.

Mi question is, how to set the focus to an input element after executing dhx.ui (…). E.g. after validating a form I want to set the focus to an input with a wrong value.

What can I do?

Thank you in advance
Horst Mürdter
CrossData-Tools

Hello,

how to set the focus to an input element after executing dhx.ui (…).

$$(‘myform’).item(“field_a”).focus = true;
$$(‘myform’).focus();

E.g. after validating a form I want to set the focus to an input with a wrong value.

[code]dhx.ui({
{
view:“form”, id:“myform”, data:[
{ type:“text”, name:“field_a”,…},

{ type:“formbutton”, click:"$$(‘myform’).validate()",…}
],
rules:{
field_a:dhx.rules.isNotEmpty
}
}
});

$$(‘myform’).attachEvent(“onValidationError”, function(key, obj){
$$(‘myform’).item(key).focus = true;
$$(‘myform’).focus();
});[/code]

Thanks Alexandra,

but you have to be aware of that this only works correct if there is no other input element with a focus property. Because the focus() function only checks with the each function if the focus property is set and focus the first element found.

If you have set in the initial code the focus property yet, this method can fail. Also if you use this function more than once it can be fail.

A workaround that I’ve found is to delete all focus properties of the form before set the focus property of the desired input element.

$$(form).data.each(function (obj){ delete(obj.focus); }); $$(form).item(el).focus = true; $$(form).focus();

Best regards

Horst Mürdter
CrossData-Tools

Hello,

I found another posibility to set the focus in a form to certain input field without to reset the focus property of all elements in a form:

[code]
// form: id of form
// el: id of element to focus on

var obj = $$(form).item(el);
var element = dhx.ui.passive[obj.type];
element.focus($$(form)._locateHTML(obj.id));[/code]

Best regards

Horst Mürdter
Crossdata-Tools