Fix TypeAhead on dijit.Dialog


/**
 * Fixes a type ahead control on a dialog box created manually using dijit.Dialog (not by extlib).
 * You should call this function after creating a dialog.
 * The TypeAhead control uses the TypeAheadReadStore to retrieve suggestions. 
 * When creating this object the url attribute is set to the action attribute of a form.
 * But when creating a dialog box it's created outside form (as the last element before the closing tag of BODY.
 * So for a dialog to work in XPages you should move it inside the FORM tag.
 * But when creating a TypeAhead store object inside a dialog box there is no form and the url is empty.
 * This function will iterate over all TypeAhead stores and fix the url attribute. 
 */
function fixTypeAheadOnDialog() {
    var allStoresIds = dojo.query("[dojoType=ibm.xsp.widget.layout.data.TypeAheadReadStore]").attr("jsId");
    var form = dojo.query("form")[0];
    allStoresIds.forEach(function(id) {
        if (typeof(window[id]) !== "undefined" && typeof(window[id].url) === "undefined") {
            window[id].url = dojo.attr(form, "action");
            window[id].formId = dojo.attr(form, "id");
        }
    });
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...