Commit 69176590 authored by Fabien Morin's avatar Fabien Morin

use XPath expression in erp5.js to put the focus on the good field instead of...

use XPath expression in erp5.js to put the focus on the good field instead of DOM. This is more clear, and I think more performant.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20000 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6a10453c
...@@ -77,24 +77,17 @@ function clickSaveButton(act) {\n ...@@ -77,24 +77,17 @@ function clickSaveButton(act) {\n
// else if no element have autofocus class, the first element wich is not the\n // else if no element have autofocus class, the first element wich is not the\n
// search field will get the focus. This is generaly the title input text of\n // search field will get the focus. This is generaly the title input text of\n
// a view\n // a view\n
\n
function autoFocus() {\n function autoFocus() {\n
var inputs = document.getElementsByTagName("input");\n var first_autofocus_expr = ".//input[@class=\'autofocus\']"\n
var input_to_focus = 0;\n var FIRST_RESULT = XPathResult.FIRST_ORDERED_NODE_TYPE\n
for (i=0;i<inputs.length;i++) {\n \n
if (inputs[i].className == "autofocus") {\n var input = document.evaluate(first_autofocus_expr, document, null, FIRST_RESULT, null).singleNodeValue;\n
input_to_focus = inputs[i];\n if (input) {\n
}\n input.focus();\n
}\n
if (input_to_focus != 0) {\n
input_to_focus.focus();\n
}else{\n }else{\n
for ( var i=0; i<inputs.length; i++ ){\n var first_text_input_expr = ".//input[@type=\'text\'][@name != \'field_your_search_text\']"\n
if (inputs[i].getAttribute("type") == "text" && inputs[i].getAttribute("name") != "field_your_search_text"){\n var first_text_input = document.evaluate(first_text_input_expr, document, null, FIRST_RESULT, null).singleNodeValue;\n
inputs[i].focus();\n first_text_input.focus();\n
break;\n
}\n
}\n
}\n }\n
}\n }\n
\n \n
......
515 511
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment