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

Confirming Button changes?

Expand Messages
  • Chris Adams
    I m attempting to replace some code with YUI Buttons and was wondering what the cleanest way is to handle the equivalent of an
    Message 1 of 2 , Nov 1, 2007
    • 0 Attachment
      I'm attempting to replace some <input type="radio"> code with YUI
      Buttons and was wondering what the cleanest way is to handle the
      equivalent of an onclick="return confirm(…)". The goal is to display a
      prompt only in certain cases where the change will cause a reservation
      to be released.

      The before* events look like they should work but they only control
      the internal state, not the button's visual state (which has already
      changed by the time the events fire).

      The code I'm currently looks like this, where BG is the ButtonGroup
      and the special buttons are always the first in the group:

      var confirmPriorityChange = function (e) {
      	if (e.prevValue.index != 0) return;
      	
      	if (!confirm("Are you sure you want to release your confirmed first
      choice reservation?")) {
      		e.newValue.set('checked', false);
      		e.newValue.blur();
      		e.prevValue.set('checked', true);
      		e.prevValue.focus();
      		BG.check(e.prevValue.index);
      		return;
      	}
      
      	BG.removeListener('checkedButtonChange');
      };
      
      BG.on('checkedButtonChange', confirmPriorityChange);
      


      This works but seems overly complicated. Am I missing a cleaner way to do this or does it seem like there really should be a beforeClick event where a simple return false would restore the button to its previous state?
    • Todd Kloots
      Chris - Sorry for the late response on this issue. There is a bug in Button that prevents before events from canceling a change to an attribute. Fortunately,
      Message 2 of 2 , Dec 5, 2007
      • 0 Attachment
        Chris -

        Sorry for the late response on this issue. There is a bug in Button that
        prevents before events from canceling a change to an attribute.
        Fortunately, there is an easy way to patch this. I created an example
        for you that demonstrate both how to apply the patch, as well as block
        the change to a ButtonGroup's checked Button as you desired:

        http://yuiblog.com/sandbox/yui/v240/examples/button/example02.html

        This bug will be fixed in the next release of Button.

        - Todd



        Chris Adams wrote:
        >
        > I'm attempting to replace some <input type="radio"> code with YUI
        > Buttons and was wondering what the cleanest way is to handle the
        > equivalent of an onclick="return confirm(…)". The goal is to display a
        > prompt only in certain cases where the change will cause a reservation
        > to be released.
        >
        > The before* events look like they should work but they only control
        > the internal state, not the button's visual state (which has already
        > changed by the time the events fire).
        >
        > The code I'm currently looks like this, where BG is the ButtonGroup
        > and the special buttons are always the first in the group:
        >
        > var confirmPriorityChange = function (e) {
        > if (e.prevValue.index != 0) return;
        >
        > if (!confirm("Are you sure you want to release your confirmed first
        > choice reservation?")) {
        > e.newValue.set('checked', false);
        > e.newValue.blur();
        > e.prevValue.set('checked', true);
        > e.prevValue.focus();
        > BG.check(e.prevValue.index);
        > return;
        > }
        >
        > BG.removeListener('checkedButtonChange');
        > };
        >
        > BG.on('checkedButtonChange', confirmPriorityChange);
        >
        >
        >
        > This works but seems overly complicated. Am I missing a cleaner way to
        > do this or does it seem like there really should be a beforeClick
        > event where a simple return false would restore the button to its
        > previous state?
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.