Loading ...
Sorry, an error occurred while loading the content.

Submit Dialog on Enter Key Press

Expand Messages
  • Frank
    I have two buttons defined on my dialog, is it possible to define that one of them will be executed (it s handler) when the Enter key is pressed? I did some
    Message 1 of 4 , Jun 26, 2008
    • 0 Attachment
      I have two buttons defined on my dialog, is it possible to define that
      one of them will be executed (it's handler) when the Enter key is pressed?

      I did some searching and this issue seems to have come up before but I
      couldn't find a proper solution in the posts.
    • Steve
      ... pressed? ... There may be a way that is better, but one option is to create a YAHOO.util.KeyListener with the proper scope for the dialog window.
      Message 2 of 4 , Jun 26, 2008
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, "Frank" <fsa3@...> wrote:
        >
        > I have two buttons defined on my dialog, is it possible to define that
        > one of them will be executed (it's handler) when the Enter key is
        pressed?
        >
        > I did some searching and this issue seems to have come up before but I
        > couldn't find a proper solution in the posts.
        >


        There may be a way that is better, but one option is to create a
        YAHOO.util.KeyListener with the proper scope for the dialog window.

        http://developer.yahoo.com/yui/examples/container/keylistener.html
      • bretlevy
        If the button is of type submit, it should submit on an enter key press (no special key listener required). I, for one, don t like that happening! I ve found
        Message 3 of 4 , Jun 26, 2008
        • 0 Attachment
          If the button is of type submit, it should submit on an enter key
          press (no special key listener required).

          I, for one, don't like that happening! I've found that unseasoned
          users hit enter at the end of a text box, for example a user name
          field, and then get an error message because they haven't yet entered
          a password (for example). This is worse than not having the enter
          key submit, imho.

          For those that don't ever want a form to submit "accidentally", I've
          found the only universal solution (ie, works in all browsers) is to
          encode this:

          onsubmit="javascript:return(false);"

          into every <form> tag. Now the form can only be submitted via script
          (even in Safari, Opera, etc!)

          ~~bret



          --- In ydn-javascript@yahoogroups.com, "Steve" <kelsey69@...> wrote:
          >
          > --- In ydn-javascript@yahoogroups.com, "Frank" <fsa3@> wrote:
          > >
          > > I have two buttons defined on my dialog, is it possible to define
          that
          > > one of them will be executed (it's handler) when the Enter key is
          > pressed?
          > >
          > > I did some searching and this issue seems to have come up before
          but I
          > > couldn't find a proper solution in the posts.
          > >
          >
          >
          > There may be a way that is better, but one option is to create a
          > YAHOO.util.KeyListener with the proper scope for the dialog window.
          >
          > http://developer.yahoo.com/yui/examples/container/keylistener.html
          >
        • Satyen Desai
          Hi, Not through configuration, but you can use the KeyListener infrastructure, to bind a listener to the Enter key, and invoke the same function which you use
          Message 4 of 4 , Jul 1, 2008
          • 0 Attachment
            Hi,
            Not through configuration, but you can use the KeyListener infrastructure, to bind a listener to the Enter key, and invoke the same function which you use for your handler (setting a scope if required).

            See:
            http://developer.yahoo.com/yui/examples/container/keylistener.html
            http://developer.yahoo.com/yui/docs/YAHOO.util.KeyListener.html

            A couple of notes:

            a). The element you're listening on does not necessarily need to be the document as in the above example. It could be the container's bounding box also, but in order for the key listener to be invoked in that case, something within the bounding box will need to have focus.

            b). I assume you're not talking about hitting Enter when the button has focus, which you'll get for free - viz. The button's 'click' listeners will get invoked if you hit Enter when the button has focus.

            Hope that helps,
            Satyen

            ________________________________________
            From: ydn-javascript@yahoogroups.com [mailto:ydn-javascript@yahoogroups.com] On Behalf Of Frank
            Sent: Thursday, June 26, 2008 9:54 AM
            To: ydn-javascript@yahoogroups.com
            Subject: [ydn-javascript] Submit Dialog on Enter Key Press

            I have two buttons defined on my dialog, is it possible to define that
            one of them will be executed (it's handler) when the Enter key is pressed?

            I did some searching and this issue seems to have come up before but I
            couldn't find a proper solution in the posts.
          Your message has been successfully submitted and would be delivered to recipients shortly.