[Proto-Scripty] Re: weird behavior w/ prototype & firefox
On Sep 29, 2:54 am, mhgrove wrote: > I want to have the button call a function which first schedules a call > to show the busy spinner after say like 5 seconds. This way if the > call to the server is fast, there's no blip on screen of the spinner > just before the page redirects. The function should also defer a call > to a function which will actually make the call to the server. And > when the call is complete, the callback which redirects the page to > the result should be invoked. Browsers already have methods that tell the user they are busy, much better to teach users to recognise that general behaviour than deal with different behaviours at each site. [...] > In any case, putting a "return false;" at the end of the method called > by the click handler on the form submit button, and then returning > that value to the form seems to cancel the submission and my code > works as expected. I'm not sure what you mean by the above, but submit listeners should be attached to the form, not the submit button. The inline version is something like: If doStuff returns false, submission is cancelled. If it returns any other value (even undefined or nul) the form will submit. The listener can of course be added dynamically using something like: form.onsubmit = function() { var form = this; // do stuff with form, decide whether to cancel submit or not if (cancelSubmit) { return false; } else { return whatever; } } The key is to use the form's submit event, not the button's click event. -- Rob --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: weird behavior w/ prototype & firefox
I want to have the button call a function which first schedules a call to show the busy spinner after say like 5 seconds. This way if the call to the server is fast, there's no blip on screen of the spinner just before the page redirects. The function should also defer a call to a function which will actually make the call to the server. And when the call is complete, the callback which redirects the page to the result should be invoked. I was just trying to get the spinner to show up and the submit button hidden when I kept running into this problem. As I said, I'm not much of a javascript hacker, so your mention that the submission is tearing down the page and thus would keep my code from working reliably was apparently what I was looking for =) I did not realize that it would be trying to submit the form; I modified how it was generated so it had no action, so i thought that it would not submit, but apparently it still does. I guess it's submitting back to the current page. In any case, putting a "return false;" at the end of the method called by the click handler on the form submit button, and then returning that value to the form seems to cancel the submission and my code works as expected. I appreciate the sanity check of pointing out that I was doing something dumb =) Thanks. On Sep 28, 12:37 pm, "T.J. Crowder" wrote: > Hi, > > A submit button sends a form to the server, tearing down the current > document and window contents and replacing them with the response from > the server. You're scheduling asynchronous calls via setTimeout which > are then happening (or not happening) before and as the window is > being torn down as part of that form submission. That's not going to > work reliably. :-) > > What is it you're actually trying to do? > -- > T.J. Crowder > tj / crowder software / comwww.crowdersoftware.com > > On Sep 28, 5:10 pm, mhgrove wrote: > > > > > I'll preface this with the fact that I am not much of a javascript > > hacker, and I'm new to prototype. So the following might be a very > > dumb question, but I couldn't find an answer to this googling around, > > I'm hoping that maybe someone here can point out what I'm doing wrong. > > > Basically, what I was trying to do before I got sidetracked trying to > > figure out why this didn't work is I have a form that the user will > > submit, the submission will usually take awhile, so rather than let > > the browser churn, I wanted to have the submit button call a function > > which would submit the form asynchronsously via an Ajax call, and then > > hide the submit button and replace it with a little spinner thing (I > > created one from ajaxload.info). > > > In trying to do this, I kept getting the error "$ is not defined" > > which made very little sense because I was pulling prototype into my > > page the same way I do on other pages on my site and it works just > > fine. After fumbling around I finally came up with the snippet of > > code pasted at the end of this email. > > > I distilled my issue down to a button in a form, which calls a > > function. This function schedules another call to what would display > > the spinner. But for the purposes of trying to figure out what I'm > > doing wrong, I just have it printing the version of prototype. > > > What I'm seeing on OSX with FF3.0 and 3.5 is that the behavior across > > clicks of the button is not consistent. Sometimes I'll click it and > > see all three alerts, sometimes only two. When I see only two, I get > > a "Prototype is not defined" error when it tries to display the third > > alert. This same code seems to work fine on Safari 4. > > > I tried some of the Function extensions of Prototype, but I get the > > same erratic behavior. > > > Am I going about this the wrong way? > > > Thanks. > > > > > > > > > > > > > > > var timeoutId = -1; > > > function doClick() { > > alert("dc prototype version: " + Prototype.Version); > > > timeoutId = setTimeout(next, 1); > > // next.delay(0.1); > > // next.defer(); > > // next.bind(this).defer(); > > // next.bind(this).delay(0.1); > > // next.delay(1); > > } > > > function next() { > > alert("n1 prototype version: " + Prototype.Version); > > alert("n2 prototype version: " + Prototype.Version); > > } > > > > > > > > > > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: weird behavior w/ prototype & firefox
Hi, A submit button sends a form to the server, tearing down the current document and window contents and replacing them with the response from the server. You're scheduling asynchronous calls via setTimeout which are then happening (or not happening) before and as the window is being torn down as part of that form submission. That's not going to work reliably. :-) What is it you're actually trying to do? -- T.J. Crowder tj / crowder software / com www.crowdersoftware.com On Sep 28, 5:10 pm, mhgrove wrote: > I'll preface this with the fact that I am not much of a javascript > hacker, and I'm new to prototype. So the following might be a very > dumb question, but I couldn't find an answer to this googling around, > I'm hoping that maybe someone here can point out what I'm doing wrong. > > Basically, what I was trying to do before I got sidetracked trying to > figure out why this didn't work is I have a form that the user will > submit, the submission will usually take awhile, so rather than let > the browser churn, I wanted to have the submit button call a function > which would submit the form asynchronsously via an Ajax call, and then > hide the submit button and replace it with a little spinner thing (I > created one from ajaxload.info). > > In trying to do this, I kept getting the error "$ is not defined" > which made very little sense because I was pulling prototype into my > page the same way I do on other pages on my site and it works just > fine. After fumbling around I finally came up with the snippet of > code pasted at the end of this email. > > I distilled my issue down to a button in a form, which calls a > function. This function schedules another call to what would display > the spinner. But for the purposes of trying to figure out what I'm > doing wrong, I just have it printing the version of prototype. > > What I'm seeing on OSX with FF3.0 and 3.5 is that the behavior across > clicks of the button is not consistent. Sometimes I'll click it and > see all three alerts, sometimes only two. When I see only two, I get > a "Prototype is not defined" error when it tries to display the third > alert. This same code seems to work fine on Safari 4. > > I tried some of the Function extensions of Prototype, but I get the > same erratic behavior. > > Am I going about this the wrong way? > > Thanks. > > > > > > > > > var timeoutId = -1; > > function doClick() { > alert("dc prototype version: " + Prototype.Version); > > timeoutId = setTimeout(next, 1); > // next.delay(0.1); > // next.defer(); > // next.bind(this).defer(); > // next.bind(this).delay(0.1); > // next.delay(1); > } > > function next() { > alert("n1 prototype version: " + Prototype.Version); > alert("n2 prototype version: " + Prototype.Version); > } > > > > > > > > > > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---