skube,
This is not a limitation, but a specific design decision. If you're
replacing the options in a select box you are in affect also changing the
value (or at least potentially changing) the value since you now have a
completely new set of values in the box.

Therefore, to ensure that dependency attached to the behavior are correctly
carried through the change callback is fired.

For example, let's say had 3 linkselects in your chain. Select 1 changes the
options in Select 2 and Select 2 changes the options in Select 3. When you
change the value in Select 1, the options in Select 2 will change, however
the options in Select 3 will also correctly change to reflect the new value
in Select 2.

However, if you *really* need to avoid the callback from running, the
replaceOptions() method does have a second argument you can set to false for
preventing the change callback from running. However, this really should be
the exception to the rule and should only be used if you're going to end up
with some kind of circular logic.

-Dan

On Tue, Aug 4, 2009 at 2:54 PM, skube <sku...@gmail.com> wrote:

>
> Ok, I think I have one last outstanding problem with Giva Labs'
> awesome Linkselect plug-in. I'm wondering if it is a limitation of the
> plug-in or if I am simply doing something wrong.
>
> I am using one select to update another and everything works
> perfectly. However, I am finding the "change" function fires when I
> use "replaceOptions" to update the second select even though I'm
> simply re-initiating the second select with a new set of options. I
> think the "change" function should only fire when I do I physically
> select another option in the second select and not every time I update
> the first select.
>
> I've recreated a cut/paste demo to illustrate the point below. As you
> can see, the alert occurs when changing either the first or second
> select.
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
> www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
> <head>
>  <title>Test</title>
>
>        <script type="text/javascript" src="
> http://ajax.googleapis.com/ajax/
> libs/jquery/1.2.6/jquery.min.js"></script>
>        <script type="text/javascript" src="
> http://www.givainc.com/labs/lib/
> jquery.linkselect.js"></script>
>        <script type="text/javascript" src="
> http://www.givainc.com/labs/lib/
> jquery.bgiframe.js"></script>
>
>        <link type="text/css" href="http://www.givainc.com/labs/css/
> jquery.linkselect.css" rel="stylesheet" title="default" media="all" /
> >
>        <link type="text/css" href="http://www.givainc.com/labs/css/
> jquery.linkselect.style.select.css" rel="alternate stylesheet"
> title="select" media="all" />
>
>  <script type="text/javascript">
>    $(function(){
>
>        $("#one").linkselect({
>            change: function(){
>                $("#two").linkselect("replaceOptions",
> [{value:"1",text:"asdf"}, {value:"2",text:"qwer"}]);
>            }
>        });
>
>        $("#two").linkselect({
>            change: function(){
>                alert('fired prematurely');
>            }
>        });
>
>    });
>  </script>
>
> </head>
> <body>
>    <select id="one">
>        <option>option 1-1</option>
>        <option>option 1-2</option>
>        <option>option 1-3</option>
>    </select>
>    <select id="two">
>        <option>option 2-1</option>
>        <option>option 2-2</option>
>        <option>option 2-3</option>
>    </select>
>
>
>    </body>
> </html>
>

Reply via email to