Commit ce10b6f8b46add764786e509296568ff5b01dc8f

Authored by bernard
1 parent 64d48bf4

Fixed problem with not clearing watermarks on ajax form submit.

... ... @@ -447,53 +447,49 @@ $.fn.watermark = function (text, options) {
447 447 // we need to replace the form's submit function with our own
448 448 // function. Otherwise watermarks won't be cleared when the form
449 449 // is submitted programmatically.
450   - if (this.form) {
451   - var form = this.form,
452   - $form = $(form);
453   -
454   - if (!$form.data(dataFormSubmit)) {
455   - $form.submit($.watermark.hideAll);
456   -
457   - // form.submit exists for all browsers except Google Chrome
458   - // (see "else" below for explanation)
459   - if (form.submit) {
460   - $form.data(dataFormSubmit, form.submit);
461   -
462   - form.submit = (function (f, $f) {
463   - return function () {
464   - var nativeSubmit = $f.data(dataFormSubmit);
465   -
466   - $.watermark.hideAll();
467   -
468   - if (nativeSubmit.apply) {
469   - nativeSubmit.apply(f, Array.prototype.slice.call(arguments));
470   - }
471   - else {
472   - nativeSubmit();
473   - }
474   - };
475   - })(form, $form);
476   - }
477   - else {
478   - $form.data(dataFormSubmit, 1);
479   -
480   - // This strangeness is due to the fact that Google Chrome's
481   - // form.submit function is not visible to JavaScript (identifies
482   - // as "undefined"). I had to invent a solution here because hours
483   - // of Googling (ironically) for an answer did not turn up anything
484   - // useful. Within my own form.submit function I delete the form's
485   - // submit function, and then call the non-existent function --
486   - // which, in the world of Google Chrome, still exists.
487   - form.submit = (function (f) {
488   - return function () {
489   - $.watermark.hideAll();
490   - delete f.submit;
491   - f.submit();
492   - };
493   - })(form);
494   - }
495   - }
496   - }
  450 + if (this.form) {
  451 + var form = this.form,
  452 + $form = $(form);
  453 +
  454 + if (!$form.data(dataFormSubmit)) {
  455 + $form.submit($.watermark.hideAll);
  456 +
  457 + // form.submit exists for all browsers except Google Chrome
  458 + // (see "else" below for explanation)
  459 + if (form.submit) {
  460 + $form.data(dataFormSubmit, form.onsubmit || 1);
  461 +
  462 + form.onsubmit = (function (f, $f) {
  463 + return function () {
  464 + var nativeSubmit = $f.data(dataFormSubmit);
  465 + $.watermark.hideAll();
  466 + if (nativeSubmit instanceof Function) {
  467 + nativeSubmit();
  468 + } else {
  469 + eval(nativeSubmit);
  470 + }
  471 + };
  472 + })(form, $form);
  473 + } else {
  474 + $form.data(dataFormSubmit, 1);
  475 +
  476 + // This strangeness is due to the fact that Google Chrome's
  477 + // form.submit function is not visible to JavaScript (identifies
  478 + // as "undefined"). I had to invent a solution here because hours
  479 + // of Googling (ironically) for an answer did not turn up anything
  480 + // useful. Within my own form.submit function I delete the form's
  481 + // submit function, and then call the non-existent function --
  482 + // which, in the world of Google Chrome, still exists.
  483 + form.submit = (function (f) {
  484 + return function () {
  485 + $.watermark.hideAll();
  486 + delete f.submit;
  487 + f.submit();
  488 + };
  489 + })(form);
  490 + }
  491 + }
  492 + }
497 493 }
498 494
499 495 $.watermark._show($input);
... ...
Please register or login to post a comment