Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change event is triggered twice on autocomplete causing javascript error #41

Open
gledsonrabelo opened this issue Sep 4, 2013 · 2 comments

Comments

@gledsonrabelo
Copy link

When selecting a value in the JQuery UI version >= 1.9.0 the event onblur already is triggered synchronously. So call "blur()" again cause the change event trigger twice (the second trigger cause js error in wiquery-autocomplete.js).

I believe that to remove the problem it's need to delete the direct to onblur in line 137 in InnerAutocomplete subclass.

super.setSelectEvent(JsScopeUiEvent.quickScope(js.append("$(event.target).blur();")
.toString()));

The change in JQuery UI change event behavior is documented in http://jqueryui.com/upgrade-guide/1.9/#autocomplete

Thanks

@fabio-boldrini
Copy link

same problem here. On firefox I didn't have JS error, but often the autocomplete fail to update the hidden field.

@fabio-boldrini
Copy link

for fix the problem without changeing wiquery source code (or js sorucecode) i find the way to extend AutocompleteComponent and implement renderHead() for make the right call to autocomplete

JsStatement fixAutocompleteStatement() {
    StringBuilder js = new StringBuilder();
    js.append("$.ui.autocomplete.wiquery.changeEvent(event, ui,")
        .append(JsUtils.quotes(getAutocompleteHidden().getMarkupId())
    );

    Options options = Options.class.cast(ReflectionTestUtils.getField(getAutocompleteField(), "options"));
    AbstractDefaultAjaxBehavior updateAjax = AbstractDefaultAjaxBehavior.class.cast(ReflectionTestUtils.getField(this, "updateAjax"));

    if (isAutoUpdate()) {
        js.append(",'").append(updateAjax.getCallbackUrl()).append("'");
    }
    js.append(");");
    options.put("select", JsScopeUiEvent.quickScope(js.append("").toString()));
    options.put("change", JsScopeUiEvent.quickScope(js.append("").toString()));
    JsStatement jsStatement = fixStatement(options);
    return jsStatement;
}

private JsStatement fixStatement(Options options) {
    return new JsQuery(getAutocompleteField()).$().chain("autocomplete", options.getJavaScriptOptions());
}

@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);
    response.render(OnDomReadyHeaderItem.forScript(fixAutocompleteStatement().render()));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants