Create Database Object - ERROR: Cannot set property 'className' of undefined [Solved]

I am trying to create and send data to a Moralis database object.

When i try to run the following lines:

const Monster = Moralis.Object.extend("Monster"); 
const monster = Monster();

I get the following error:

moralis.js:13715 Uncaught TypeError: Cannot set property 'className' of undefined
    at ParseObjectSubclass (moralis.js:13715)

My server details:

Example Code For Replicating

Here is a simple complete example that will reproduce the error:

<html>
  <head>
    <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
    <script src="https://npmcdn.com/[email protected]/dist/moralis.js"></script>
  </head>
  <body>
    <div>
        <button id="btn-sendData">send data</button>
    </div>
    <script>
        Moralis.initialize("XXXXXXXXXXXXX MY APP ID HERE XXXXXXXXXXXXXXXXXXXX");
        Moralis.serverURL = "XXXXXXXXXX MY SERVER URL HERE XXXXXXXXXXXXXXXXXXX";
         
        // Register button
        document.getElementById("btn-sendData").onclick = sendData;

        // Send data to database
        async function sendData() {
            const Monster = Moralis.Object.extend("Monster"); 
            const monster = Monster();
            monster.set('scariness', 88);
            monster.set('size', 56);
            await monster.save()
        }
    </script> 
</body>
</html>

This is based on the Moralis Basics - Objects - Definition youtube tutorial

1 Like

=>
const monster = new Monster();

3 Likes

Nice one! Thank you so much @cryptokid !
Works perfectly now :slight_smile:

1 Like

@Yomoo , By default it seems to be allowing anyone to update the data base. I am not logged in and it is letting me update things. Presumably this section of the docs is where i would look for restricting access?

@bobbington Yes you are right. By default, all new tables are available for public editing.

The easiest way to set CLP settings is from dahboard UI:
image

Other methods are described in the documentation which you have sent, depending on what kind of data you want to restrict for editing.

1 Like

Ohh, Nice! I hadn’t noticed that button before!
Thank you so much for all the help @Yomoo and for going well beyond what my initial question was to ensure i didnt do something silly like leaving the database open to everyone :slight_smile:

1 Like

I’ve edited my answer and your reply due to the fact that I wrote the wrong information :sweat_smile:

No worries, thanks for being so diligent :slight_smile:

1 Like