I'm struggling to position a Dojo widget on the webpage

Looking for assistance with a straightforward widget:

define(["dojo/_base/declare", "dijit/_WidgetBase", "dojo/dom-construct"],
function(declare, WidgetBase, domConstruct){

    return declare("gijit.workflow.debug.combi", [WidgetBase], {
        startup: function(){
            alert("started");
        },
        buildRendering: function(){

            var container = domConstruct.create("div", {innerHTML:"test"}, this.domNode, "first");
            var rad1 = domConstruct.create("input", {type:"radio"}, container, "first");
            var rad1 = domConstruct.create("input", {type:"radio"}, container, "last");
        }
    });
});

As well as a basic loading page setup:

<!DOCTYPE html>
<html >
<head>

<link rel="stylesheet" href="../../../css/tcs-style-dijit.css" />

<script>dojoConfig = {parseOnLoad: false}</script>
<script src="../../../js/dojo/dojo.js" data-dojo-config="async: true"></script>
<!-- <script src="../../../js/gijit/workflow/debug/combi.js"></script> -->
<script>
require(["dojo/dom", "gijit/workflow/debug/combi", "dojo/parser",
        "dojo/_base/window"], function(dom, combi, parser, window) {
    var widget = new combi();
    widget.placeAt(window.body());
//  widget.startup();
});
</script>
</head>
<body id="dd" class="tcs">
</body>
</html>

A challenge arises when I encounter the following error:

Error message: Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLBodyElement.appendChild] at">http://domain: port/js/dojo/dojo.js Line 15

The issue seems to surface at the moment of trying to place the widget in the HTML:

widget.placeAt(window.body());

I'm struggling to pinpoint the root cause of this problem and any guidance would be greatly appreciated.

Answer №1

When you call window.body(), the DOM has not been parsed yet, so it will return undefined. To address this issue, make sure to include the dojo/domReady! plugin as the last module loading:

require([
    "dojo/dom",
    "gijit/workflow/debug/combi",
    "dojo/parser",
    "dojo/_base/window",
    "dojo/domReady!"  // ==> wait for the DOM to be ready
], function(dom, combi, parser, win) {
    var widget = new combi();
    widget.placeAt(win.body());
    widget.startup();
});

It is recommended to avoid hiding the window object by using a local variable named win instead of assigning dojo/_base/window module to it.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to ensure that my multiple choice code in CSS & JS only allows for the selection of one option at a time? Currently, I am able

I'm currently facing a small issue that I believe has a simple solution. My knowledge of Javascript is limited, but I am eager to improve my skills in coding for more visually appealing websites. My problem lies in the code snippet below, where I am ...

Shuffle the elements within each container in the DOM

Currently, I am focusing on designing a card-based layout where each card contains details about the product. One important detail is the phone number, which is displayed in the format 555-555-5555. My current goal is to clear the text value of the phone ...

Checking the alignment of celestial bodies for an array of entities

Seeking to implement validation for a form featuring checkbox selections with corresponding number inputs. When a user selects a profession checkbox, they must enter the number of years of experience they have in the input next to it. The array structure i ...

What is the process for transferring an image from the main page to another?

For days, I have been searching for an answer without any luck. It seems that I just can't wrap my head around it and apply it to what I am working on. Currently, I am using PHP to store images on the server when a user hits submit. My goal is to dis ...

Ways to align the label at the center of an MUI Textfield

My goal is to center the label and helper text in the middle of the Textfield. I managed to achieve this by adding padding to MuiInputLabel-root, but it's not responsive on different screen sizes (the Textfield changes size and the label loses its cen ...

What is causing my background image to move upward when I include this JavaScript code for FlashGallery?

There's an issue on my website where adding a flash gallery script is causing the background image to shift unexpectedly. You can view the affected page here: The culprit seems to be the "swfobject.js" script. I've identified this by toggling t ...

JavaScript: creating and saving unique random selections without repetition

Currently, I am grappling with using Javascript to generate an array, select two distinct random elements from the array, and then allocate these selected values to an HTML table. My strategy has involved initializing an array, picking a random value, gene ...

What is the best method for installing Raphael.js using bower?

Currently, I am attempting to incorporate Raphael.js into my project in a highly modular manner. Since Raphael has a registered bower component, utilizing that option seemed like the most logical choice. Following some instructions from the Snap.svg readm ...

Is it possible to constantly retrieve data at one-second intervals in NextJS using getServerSideProps?

Is there a way to continuously fetch API data in NextJS using SSR (getServerSideProps) every second? This would involve the client making a request to the server every one second to receive the most up-to-date API data. Any suggestions? export const getS ...

Is there an issue with the onClick event in React Buttons when they are generated using the .map()

Is the button created in the .map() function expired after the function ends? It does not seem to work. The code reads from a JSON file that stores an array, loops through it to display items including the button. When clicked, the button should set the d ...

Trigger jqGrid to apply the filter aggressively

Currently working with jqGrid 4.1.2 and I am attempting to automatically trigger filters on $(document).ready() My goal is to populate a filter field with values and simulate pressing the "enter" key so that jqGrid will filter accordingly. I have success ...

Transform the structure of an object using Ramda from its original form

Is it possible to transform an object by modifying and filtering it to create a different shape that is easier to work with after making an API request? I've been struggling to find elegant solutions that don't involve using path and prop for eve ...

Navigating to a particular value in Vue: A step-by-step guide

In my Vue application, I have a basic table structure: <tbody> <tr v-for="(item, index) in items"> <td> ... </td> </tr> </tbody> The items are dynamically added using the unsh ...

Updating the Bootstrap entry dynamically within the @NgModule module

My web application has a specific requirement where it can only be accessed through example.com/index.html without any parameters. The backstory behind this restriction is quite lengthy, so let's not delve into that. Within the index.html file, I have ...

Setting up a new folder in the internal storage within a React Native Expo environment

In my React Native Expo project, I am utilizing two functions to store data in a JSON file and then save the file to internal storage. However, the code currently asks for permission to store inside a chosen folder, but does not create the "ProjectName" fo ...

Tips for customizing the appearance of your browser's scroll bar:

Is there a way to customize the browser scroll bar using html, css, and js similar to how Chrome does with Control + F? https://i.sstatic.net/62Hju.png I have experimented with adding a fixed position div creating a linear gradient style for the scroll ...

Display a hidden form field in Rails depending on the object's value

As a programmer learning Ruby on Rails without much knowledge of Javascript, I faced a problem with a form that creates an object called Unit. This Unit model is related to Category which in turn is related to Product. The issue was that while selecting a ...

Obtain data in JSON format through an xmlhttp request

I originally used jQuery for this task, but I now want to switch to regular JavaScript as I'll be incorporating it into phonegap. I aim to avoid relying on different JS frameworks every time I make a server request, which could potentially improve per ...

Mastering smooth zoom and scroll effects in JavaScript without any flickering

My web application has a zoom feature that scales some absolutely positioned DIVs while keeping the scroll position intact. However, during the animated zooming, there is a noticeable flickering effect where the boxes seem to jump up and down slightly. I a ...

Oops! Make sure to call google.charts.load before calling google.charts.setOnLoadCallback to avoid this error

My HTML file includes the following imports: <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> ...