Skip to Content
Menú
This question has been flagged
1 Respondre
4537 Vistes

Hi,

I want to show a field only when a particular key is pressed (eg: Alt+p). How could I achieve this in odoo9?

Avatar
Descartar
Best Answer

- load your own javascript file with something like:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend" name="mis_builder" inherit_id="web.assets_backend">
  <xpath expr="." position="inside">
 <script type="text/javascript" src="/path_to_your_js.js">
                </script>
             </xpath>
         </template>
     </data>
</openerp>

Then in that javascript file, do something like

var map = {x: false, y: false, z: false};

where X, Y and Z are the value of the keypress event of the key you want the user to press (for exemple, "enter" is 13)

then something 

$(document).keydown(function(e) {
 if (e.keyCode in map) {
         map[e.keyCode] = true;
         if (map[x] && map[y] && map[z]) {
          //code to execute when X, Y and Z are pressed. Again, X Y and Z are the value of the keypress event
}).keyup(function(e) {
     if (e.keyCode in map) {
         map[e.keyCode] = false;
}});

 

The code to execute should, in some way, hide or display the field you want. You'll need to find a solution to use a CSS selector to find that field exactly, but that should not be hard ;).


Avatar
Descartar