AJM.MARTINEZ
AJM.MARTINEZ

Reputation: 479

Set focus on autocomplete field

I have a form that has some fields. One field is autocomplete . The field is filled with information from a table

$f->addField('autocomplete','idfield','Field')->setValueList( $this->api->db->dsql()  
 ->table('items')->field('id,name')->do_getAssoc() );

I'm trying to set the focus on that field when the page loads.

I have did this

On top of the page

$p->js()->_load('seteo_foco');

And then

seteo_foco.js

$(function(){
  $("select:first").focus();
})

But this does not work.

Anybody can help ?

Thanks

Upvotes: 1

Views: 105

Answers (1)

Kostiantyn
Kostiantyn

Reputation: 1853

Try TRUE like $this->js(true)->_load('seteo_foco'); to load js file.

But in your js code your selector is incorrect. You need to specify you unique field. I'd use something like $form->getElement('field_name')->js(true)->focus(); on the page after the form has been initialized.

Upvotes: 1

Related Questions