Changeset 494


Ignore:
Timestamp:
May 28, 2010, 2:15:34 PM (13 years ago)
Author:
duh
Message:
  • fixed a nasty IE bug that caused select elements with onchange events execute twice, hence performing two ajax calls in the wizard which resulted in unexpected behaviour. Workaround is to insert a javascript check to see if the time between two subsequent onchange ajax calls is more than 100 miliseconds, otherwise the subsequent call will be ignored.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/taglib/dbnp/studycapturing/WizardTagLib.groovy

    r484 r494  
    131131
    132132                // strip the button part to only leave the Ajax call
    133                 button = button.replaceFirst(/<[^\"]*\"jQuery.ajax/, 'jQuery.ajax')
     133                button = button.replaceFirst(/<[^\"]*onclick=\"/, '')
    134134                button = button.replaceFirst(/return false.*/, '')
    135135
     
    194194
    195195                // render new body content
     196                //      - this JavaScript variable is used by baseElement to workaround an IE
     197                //        specific issue (double submit on onchange events). The hell with IE!
     198                //        @see baseElement
     199                out << '<script type="text/javascript">var lastRequestTime = 0;</script>'
    196200                out << render(template: "/wizard/common/tabs")
    197201                out << '<div class="content">'
     
    211215println ".rendering [" + inputElement + "] with name [" + attrs.get('name') + "] and value [" + ((attrs.value) ? attrs.get('value').toString() : "-") + "]"
    212216                // work variables
     217                def internetExplorer = (request.getHeader("User-Agent") =~ /MSIE/)
    213218                def description = attrs.remove('description')
    214219                def addExampleElement = attrs.remove('addExampleElement')
     
    222227
    223228                        // add onChange AjaxSubmit javascript
    224                         attrs.onChange += ajaxSubmitJs(
    225                                 [
    226                                         functionName: ajaxOnChange,
    227                                         url: attrs.get('url'),
    228                                         update: attrs.get('update'),
    229                                         afterSuccess: attrs.get('afterSuccess')
    230                                 ],
    231                                 ''
    232                         )
     229                        if (internetExplorer) {
     230                                //              - somehow IE submits these onchanges twice which messes up some parts of the wizard
     231                                //                (especially the events page). In order to bypass this issue I have introduced an
     232                                //                if statement utilizing the 'before' and 'after' functionality of the submitToRemote
     233                                //                function. This check expects lastRequestTime to be in the global Javascript scope,
     234                                //                (@see pageContent) and calculates the time difference in miliseconds between two
     235                                //                onChange executions. If this is more than 100 miliseconds the request is executed,
     236                                //                otherwise it will be ignored... --> 20100527 - Jeroen Wesbeek
     237                                attrs.onChange += ajaxSubmitJs(
     238                                        [
     239                                                before: "var execute=true;try { var currentTime=new Date().getTime();execute = ((currentTime-lastRequestTime) > 100);lastRequestTime=currentTime;  } catch (e) {};if (execute) { 1",
     240                                                after: "}",
     241                                                functionName: ajaxOnChange,
     242                                                url: attrs.get('url'),
     243                                                update: attrs.get('update'),
     244                                                afterSuccess: attrs.get('afterSuccess')
     245                                        ],
     246                                        ''
     247                                )
     248                        } else {
     249                                // this another W3C browser that actually behaves as expected... damn you IE, DAMN YOU!
     250                                attrs.onChange += ajaxSubmitJs(
     251                                        [
     252                                                functionName: ajaxOnChange,
     253                                                url: attrs.get('url'),
     254                                                update: attrs.get('update'),
     255                                                afterSuccess: attrs.get('afterSuccess')
     256                                        ],
     257                                        ''
     258                                )
     259                        }
    233260                }
    234261
Note: See TracChangeset for help on using the changeset viewer.