Having a bit of a nightmare getting a jQuery UI to...
# suitescript
p
Having a bit of a nightmare getting a jQuery UI to load so that I can make a pop up with a suitelet. So far i've got a UE script that creates a sublist button linked to a client script and also loads a custom HTML file into an inlinehtml field that is added on beforeload, this HTML file contains links to the jquery ui file. In the client script i've got a fairly standard jQuery("#_add_dialog").dialog call that is aimed at the div added in the previous HTML file, however when activating the button that contains the dialog code I get the following error "bootstrap.js:184 Uncaught TypeError: jQuery(...).dialog is not a function". can anyone see an obvious mistake in that approach?
b
you would need to share your setup
especially how the dependencies are handled
p
This is my UE script that adds the button / field / html
Copy code
if(scriptContext.type != scriptContext.UserEventType.VIEW) {
                scriptContext.form.clientScriptFileId = 44511;
                var list = scriptContext.form.getSublist('item');
                list.addButton({
                    id: 'custpage_add_po_items',
                    label: 'Add PO Items',
                    functionName: 'addPOItems'
                });

                const dialogHTMLField = scriptContext.form.addField({
                    id: 'custpage_jqueryui_add_dialog',
                    type: 'inlinehtml',
                    label: 'add po lines html field'
                });
                dialogHTMLField.defaultValue = file.load({
                    id: 'SuiteScripts/ContractPurchasing/dialoghtml.html'
                }).getContents();
            }
The contents of the HTML file:
Copy code
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="<https://code.jquery.com/ui/1.12.1/jquery-ui.js>"></script>
<div id="_add_dialog" title="Add dialog"></div>
<style type="text/css">
    .ui-dialog .ui-dialog-title {
        text-align: center;
        width: 100%;
    }
</style>
The Client script call
Copy code
jQuery("#_add_dialog").dialog({
                    width: 400,
                    height: 450,
                    modal: true,
                    src: "<https://xxx-sb1.app.netsuite.com/app/site/hosting/scriptlet.nl?script=444&deploy=1>",
                    close: function () {
                       // $("#thedialog").attr('src', "about:blank");
                    }
                });
s
have you tried logging the contents of the file before setting, to make sure you are actually putting the correct value in the field
you error seems to indicate it doesnt think
jQuery("#_add_dialog")
is anything, you can test this in the console, if that is nothing then your problem is before you get to the client
p
The contents of the html file are being loaded into the form successfully
jQuery UI is showing up as an active source also
b
the contents of the html and the code look reasonable
though the architecture is flawed
it looks like an attempt to add jquery ui to netsuite's jquery library
you can probably get it to work, but ultimately jquery is netsuite's dependency and they can do whatever they want to it
p
True, I wasn't sure what the consequences of loading in a more recent version of jQuery would do, so started with just UI for the dialog function
I'm more than open to anything that achieves the same end result of a nice modal if you would suggest a better method
s
You could try adding a
type="text/javascript"
before the
src
inside the script tag, not sure that is really the problem
b
i personally stopped with the script tags
and switched to using the client script's define to handle dependencies
p
I don't suppose you would have an example of how that works? sounds better than this inline hacking
b
it allows you to add your own version of jQuery without playing with no conflict
first step is adding your own jQuery to the dependencies of your client script
that will involve setting up a require Configuration using the path so you can use the jquery alias
same thing as Naming a Custom Module, except you dont need a shim since jquery supports amd
p
I will have a read through the docs now