Alpha Video Training
Results 1 to 15 of 15

Thread: How to avoid user press "backspace" and "delete"? keycode

  1. #1
    Member
    Real Name
    Jenny Gong
    Join Date
    Jul 2013
    Posts
    282

    Default How to avoid user press "backspace" and "delete"? keycode

    I have a textbox in grid, in some case, this box does not user delete or modify. So i put "return false'" in onKeyPress/Down, onFcous, onSelect JS event...

    It does work for not allowing user to modify... but when i press "Backspace/Delete", it still delete variables in that textbox...

    I also tried the following code...which still does not work.. Anyone knows the answer? Thank you very much!

    var keyCode = event.charCode || event.keyCode;
    if (keyCode==8)||(keyCode==127){
    return false;
    }

  2. #2
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    Could you use get value and set value to just keep filling the field in with what was there before the user tried to modify it? In practice, it would happen so quickly that it would look like the delete/backspace didn't work.

  3. #3
    "Certified" Alphaholic
    Real Name
    Andy Gill
    Join Date
    Jul 2011
    Location
    Barbados
    Posts
    1,029

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    In onclick event, put this.blur();

  4. #4
    Member
    Real Name
    Jenny Gong
    Join Date
    Jul 2013
    Posts
    282

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    This is cool! Unfortunately, it still allows highlight it, and delete...

  5. #5
    Member
    Real Name
    Jenny Gong
    Join Date
    Jul 2013
    Posts
    282

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    I tried it again...it seems not 100% working everytime...sometimes.. you still can put your mouse curse at the beginning of that textbox, and then you press "delete", if you have full keyboard..it will still delete everything in that textbox...

  6. #6
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    Looking at it again, I think maybe your code was just messed up. Try this:

    Code:
    var keyCode = event.charCode || event.keyCode;
    if (keyCode==8||keyCode==46)
    {
    return false;
    }
    I changed the format of the if/or and that I used code 46 instead of 127.

  7. #7
    Member
    Real Name
    Jenny Gong
    Join Date
    Jul 2013
    Posts
    282

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    i tried it with 46...not lucky...

  8. #8
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    The format of the "if statement" made a difference too. Copy my complete code back into your event, not just changing the 127. The code above in the onKeyDown event works perfect in my test grid. In my case I am unable to backspace or delete. It seems to work just fine.

  9. #9
    "Certified" Alphaholic
    Real Name
    Andy Gill
    Join Date
    Jul 2011
    Location
    Barbados
    Posts
    1,029

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    sorry, I meant onfocus event.

  10. #10
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    Also, if you don't want any keys at all to work I think you can try this instead of the "return false"

    Code:
    var keyCode = event.charCode || event.keyCode;
    if (keyCode)
    {
    return false;
    }
    I think this should keep you from being able to press any key in there. It let's me click in there but won't let me delet/backspace/other key.

  11. #11
    Member -Jinx-'s Avatar
    Real Name
    Jinx
    Join Date
    Jul 2012
    Location
    Wisconsin
    Posts
    963

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    Quote Originally Posted by agillbb View Post
    sorry, I meant onfocus event.
    I tried yours and it's too slow Andy. If you're quick you can click and delete/backspace.


    ETA: Nevermind. It works in the onFocus I think. I should have known better. LOL

    Can still right click and "cut" though.

  12. #12
    Member
    Real Name
    Jenny Gong
    Join Date
    Jul 2013
    Posts
    282

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    Not working either...But thank you anyway!!! i think so far this.blur(); is the best solution...though still have issue...

  13. #13
    "Certified" Alphaholic
    Real Name
    Andy Gill
    Join Date
    Jul 2011
    Location
    Barbados
    Posts
    1,029

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    You are skillful - I can't duplicate this if I add onfocus="this.blur();" as an attribute to an input field in Firefox. Why don't you share what browser & A5 build number you are using.

  14. #14
    Member
    Real Name
    Jenny Gong
    Join Date
    Jul 2013
    Posts
    282

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    i am using IE browser to test and Alpha V12, I do heard Firefox has no problem with this.

  15. #15
    "Certified" Alphaholic
    Real Name
    Andy Gill
    Join Date
    Jul 2011
    Location
    Barbados
    Posts
    1,029

    Default Re: How to avoid user press "backspace" and "delete"? keycode

    The easiest way to disable a field is to put 1=0 in the client-side enable setting.

Similar Threads

  1. append.m_exp24 = convert_type(time("",now()),"c") returns error -"improper characte
    By Freewilly3d in forum Alpha Five Version 11 - Desktop Applications
    Replies: 4
    Last Post: 04-08-2013, 09:12 PM
  2. "Object Is Not Defined" Error When I Use "Close Form" in the "OnInit"
    By nigeldude in forum Alpha Five Version 11 - Desktop Applications
    Replies: 5
    Last Post: 03-23-2013, 05:22 AM
  3. "Field Display Formatting" is Lost when "Pre-fetch data for Detailed View = Active"
    By PhillipS in forum Application Server Version 9 - Web/Browser Applications
    Replies: 0
    Last Post: 07-23-2009, 11:02 PM
  4. form.view("fName","","","center","center")
    By reynolditpi in forum Alpha Five Version 9 - Desktop Applications
    Replies: 5
    Last Post: 07-15-2008, 12:37 AM
  5. "Add" and "Save" buttons don't stay on "Self" page
    By Scholin in forum Application Server Version 8
    Replies: 2
    Last Post: 02-05-2008, 08:50 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •