Triggering from actions from Keyboard

  • 12 September 2013
  • 3 replies
  • 1 view

Badge +1

Hi,


I have a save button on my form that saves a number of views.


Is it possible to trigger this button from a Keyboard command?


 


 


3 replies

Badge +6

It is not possible OOTB. But it might be achievable by injecting javascript using the Literal control on K2 Underground

Badge +4

You can use the mousetrap library - http://craig.is/killing/mice


 


Quick example:


1. Copy the mousetrap library from here http://cdn.craig.is/js/mousetrap/mousetrap.min.js?0b092


2. Paste it under C:...K2 blackpearlK2 SmartForms DesignerScript and C:...K2 blackpearlK2 SmartForms RuntimeScript


3. Create a SmartObject Smartbox called Employee with the following properties:


  ID Autonumber


  Name text


  Age Number


4. Create Form EnterKey and drag and drop a Button in the Canvas and set the Name as ButtonABC


5. Associate a click rule with the ButtonABC and set and configure 'Execute a SmartObject method' as action. Configure it to call the smartobject Employee created on 3.


6. Drag and drop a data label on the Form EnterKey canvas and create and associate the following expression:


 <script>$.getScript('/Designer/Script/mousetrap.min.js', function(data, textStatus, jqxhr) {


                                 Mousetrap.bind('enter', function() {  $('a[name=ButtonABC]').click();    });


                              });


</script>  


// setting an event for the enter key


7. Run the Form and press Enter. You should have your Employee smartbox updated with the data configured on 5.


 


Tested with K2 SF 1.0.2, Chrome and IE9.


 


Cheers,


Tiago


 

Badge +4

An updated version of the script provided on my last post:


 


<script>


$.getScript('/Designer/MyCustomScripts/mousetrap.min.js',
function(data,
textStatus, jqxhr) { 


Mousetrap.stopCallback =
function(e, element, combo) { return false; };
/* This will allow the enter key event to be triggered even when the focus in on a input control */


Mousetrap.bind('enter',
function() {  $('a[name=btnSubmit]').click();
return false;   });


 


     }); </script>


 


Additionally, you might want to set the data label with the expression on a dummy view and set your submit buttons on the forms with the name btnSubmit. Then you just need to drag and drop the dummy view, set it as invisible, and re-use the dummy view across all your forms.


As a best practise, the path to the script should be specified on a env field.


 


 

Reply