5 Replies Latest reply: Nov 14, 2012 2:00 AM by fac586 RSS

    No Submit when Enter pressed in Textfield - update in 4.2?

    TobiP
      Greetings to the Community!

      There has been this issue, that unwantingly a page submits, when you press enter in a Textfield. (E.g. you want to validate the input with javascript, than give an appropriate Usermessage on error.) - Even thou you apply the option "No Submit when Enter Pressed" in the Item dialog.

      There has been a workaround, that you must add a 2nd textfield to the page, so that that option takes effect. - Which appeares to me as not so nice a solution.

      So I am just wondering about three things:

      1) in Javascript there is the function: e.preventDefault();
      I have tried this out, but its not working. Can anyone tell me, if this cant be applied in APEX at all, and for what reasons?

      2) If you have an interactive report on the page, pressing enter in that search field sometimes also submits the page. So having this and a text field should stop the submit process. It still doesnt. Can anyone say what to do against it?

      3) Are there plans to change this problem with the 4.2 release?

      Honestly I am a bit frustrated, because validating a Date input with javascript - in APEX - without several other stuff to happen that you dont want - turns out to such a huch hassle that I am about to implement my own html input field plus my own html button. But whats the point using APEX then with all its features?

      Thanks for any hints and best regards

      PS: our current Apex version is 4.0.1, but we are about to upgrade to 4.2
        • 1. Re: No Submit when Enter pressed in Textfield - update in 4.2?
          jariola
          Hi,

          This might help
          http://dbswh.webhop.net/htmldb/f?p=BLOG:READ:0::::ARTICLE:2525800346147859

          Please read also comment from apodictus

          Regards,
          Jari
          -----
          My Blog: http://dbswh.webhop.net/htmldb/f?p=BLOG:HOME:0
          Twitter: http://www.twitter.com/jariolai
          • 2. Re: No Submit when Enter pressed in Textfield - update in 4.2?
            Joni Vandenberghe
            Odd bug, let's hope it gets fixed fast. In the mean time I suggest you use:
            $('#ITEM_NAME').bind('keypress',function(e){e.preventDefault()});

            to prevent the default action (page submit) when enter pressed on an item.
            • 3. Re: No Submit when Enter pressed in Textfield - update in 4.2?
              Patrick Wolf-Oracle
              Hi,

              please see http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2 or the discussion at http://stackoverflow.com/questions/1370021/enter-key-on-a-form-with-a-single-input-field-will-automatically-submit-with-ge

              Long story short, this is not an APEX bug, it's a browser default behavior.

              To workaround this problem you should be able to use the following JavaScript code to disable the submit.
              apex.jQuery("#P1_ABC").on("keydown", function(pEvent) {
                if (pEvent.keyCode === 13) {
                  return false;
                }
              });
              Regards
              Patrick
              -----------
              My Blog: http://www.inside-oracle-apex.com
              APEX Plug-Ins: http://apex.oracle.com/plugins
              Twitter: http://www.twitter.com/patrickwolf
              • 4. Re: No Submit when Enter pressed in Textfield - update in 4.2?
                TobiP
                Hi guys!

                Thanks for all the good links. I will study them.
                @ Joni: That code you suggest I urge you to try it out yourself! ;) Its not that simple!

                In the meantime I also found a similar solution to pressing a button (same process as pressing enter in textfield).
                With 4.2 you have the Option: Action "Definded by Dynamic Action".
                There also, the page gets submittet, wheather you want to or not, because per definition every html button submits a page, when there is a form on it, and all Apex-buttons are declares as <botton>...</button>, instead of <input type="button"... >, which is a better standard.
                So you have to go with the old: Action "Redirect to Url" and in the Url write: "javascript:return false;", just like Partick suggests for input field. ... also a bit odd a solution thou.
                • 5. Re: No Submit when Enter pressed in Textfield - update in 4.2?
                  fac586
                  TobiP wrote:

                  There also, the page gets submittet, wheather you want to or not, because per definition every html button submits a page, when there is a form on it, and all Apex-buttons are declares as <botton>...</button>, instead of <input type="button"... >, which is a better standard.
                  Unclear. Which do you consider "a better standard"? Why?