EasyUI Forum
September 14, 2025, 09:26:00 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: reset textbox on escape (esc) key  (Read 7852 times)
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« on: September 23, 2015, 03:30:47 AM »

A textbox exists with text "test" in it. The user begins to type in that textbox and presses escape key to undo editing such that the value "text" is restored again.

In keydown bind function, I call reset on textbox but that sets the textbox empty:

Quote
$.fn.textbox.defaults = $.extend({},$.fn.textbox.defaults,{
   inputEvents:$.extend({},$.fn.textbox.defaults.inputEvents,{
      keydown:function(e){
         if(e.keyCode == 27){
            var target = e.data.target;
            $(target).textbox('reset');
         }
      }
   })
});

How can I reset the value that was there prior to edit?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: September 23, 2015, 08:08:18 AM »

To set the initialized value, you have to set the 'value' when creating the textbox. Please take a look at the code below, the textbox is created with an initialized value. When calling 'reset' method, the value will be reset to its original value. i.e. 'initialized value'.
Code:
$('#tt').textbox({
  value: 'initialized value'
});
Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #2 on: September 25, 2015, 04:57:09 AM »

The textboxes are defined once and filled conditionally using 'initValue'. The user may edit the text which is saved onChange. Now I want to add 'escape key' functionality to reset the textbox with value that was set prior to edit. I have made an example of what I mean:

http://jsfiddle.net/2hy9jz2h/3/

If you try to edit say street for employee1 and press escape, the textbox is set to empty. How can I use the option 'value' here? I did try to set the value using
Code:
        $('#streetTB').textbox('options').value = 'some value'; 
but that doesn't work.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: September 25, 2015, 09:11:51 AM »

Please try this updated example http://jsfiddle.net/2hy9jz2h/4/
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!