Square brackets around my email address in a collection

Hi all. I suspect this is a bit of a nube question but I really can’t find an answer anywhere.

As users are registering for my site, using the register() method, I am also taking the time to write their email address and a couple of other items to another collection also. Was using the Contacts collection but accessing it is too challenging.

When I have written to the collection, the email field shows what you see in the image below. The two emails with alerts were input through the code I wrote and the other one was entered directly into the collection as an admin.


When I hover over the yellow alert box, it shows this dialog:

I am listing my code below, hopefully someone can tell me what I am doing wrong? The email address turns up fine in the PrivateMembersInfo collection…placed there by register()…but not when I insert().

import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixWindow from 'wix-window';

$w.onReady(function () {
 
/* some other code runs here to build a lit for a pull down...it works fine and I removed it for clarity */
 
 //await submit button click
 $w("#registerButton").onClick( (event) => {
 
 var email = $w("#email").value;
 var password = $w("#password").value;
 var first = $w("#firstName").value;
 var last = $w("#lastName").value;
 var organisation = $w("#orgDropdown").value;
 var role = $w("#role").value;

 wixUsers.register(email, password, {
 contactInfo: {
 "firstName":first,
 "lastName":last,
 "emails":[email],
 "YourRole":role,
 "Organisation":organisation, 
 }
 } )
 .then( (result) => {
 let resultStatus = result.status;

 let toInsert = {
 "email":email,
 "firstName":first,
 "lastName":last,
 "org":organisation,
 };

 wixData.insert("IndividualsInfo", toInsert)
 .then( (results) => {
 let item = results; //see item below
 })
 
 .catch( (err) => {
 let errorMsg = err;
 });

 wixWindow.lightbox.close();
 wixWindow.openLightbox("Successful Reg");
 } ); 
 } );
 
});

It looks like you put the email in an array. But I don’t see it in the code you posted, so you probably did it somewhere else (maybe you wrote a data hook for this collection?)

All the relevant code is there JD…I haven’t touched the email variable anywhere else. The only hook on the collection is to concatenate the names to get a full name. Very weird.

When I switch the toInsert code to

“email” : email [ 0 ]

it just shows me the first letter of the email address in the collection.

Email is being collected from a text input box set to type: “email” in the settings for that element. Is there perhaps something caused by that do you think? If so, then how would I fix it? Any idea?

Simon.

I don’t see a problem with your code. So - no explanation.

@jonatandor35 :cry:

Is there a way to fix this with some javascript code and a hook perhaps? Really need some help here.

You’ll have to locate the problem first.