Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How can I show a field only when a particular key is pressed in odoo9?

By
Sebin Siby
on 9/1/16, 4:56 AM 79 views

Hi,

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

0
Jerome Guerriat
On 9/6/16, 11:02 AM

- 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 ;).


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/1/16, 4:56 AM
Seen: 79 times
Last updated: 9/6/16, 11:02 AM