Page 1 of 1

Landing in the right field when editing a record

Posted: 2015-06-24 00:12
by wilmira
Hello everybody,

I wonder if it is possible to land in the field that we want to edit instead of the first field of the record. That is, if we have a table with a record containing the fields: name, address, email, telephone, and then we want to edit the telephone field, when we click over that field, the program will take us to the detail view of the table and our cursor will land on the record we have just clicked.

Could it be possible?

Wilfredo

Re: Landing in the right field when editing a record

Posted: 2015-06-24 20:46
by a.gneady
Open the file "hooks/tablename-dv.js" in a text editor (where tablename is the name of the concerned table -- create that file in the hooks folder if it doesn't already exist), and add this code:

Code: Select all

$j(function(){
    $j('#phone').focus();
})
Assuming your field name is "phone".

Re: Landing in the right field when editing a record

Posted: 2015-06-24 23:54
by wilmira
Hi Ahmad,

Thank you for the code. It works great, however I cannot make it work for 2 or more fields, only for one. Can you give me an example with 2 fields?

Thanks again.

Wilfredo

Re: Landing in the right field when editing a record

Posted: 2015-06-25 12:30
by primitive_man
This technique will only work on a single field - it basically overrides the default setting -> first field in the form.

In order to work with multiple fields in Table view, you'd have to add an OnClick event to the tables fields that you wish to enable focus on.
You can do this by editing the table_templateDV.html and the table_dml.php

In the hooks/tablename-dv.js file you'd have to add a listener to see which field in your table had been clicked and then it'd change the focus() based upon this result.

Re: Landing in the right field when editing a record

Posted: 2015-06-25 19:20
by wilmira
Thank you very much.

I will try to implement what you have said.

Wilfredo