Hi Shlomi… Here’s the new POST! About previously talked… I made more tests with coding, Something is weird ! I connected a button to dataset (SUBMIT) with this code onclick event attach to the same button :
export function button12_click(event, $w) {
let gteamname = {
“gteamName”: $w(“#input26”).value,
“hteamName”: $w(“#input23”).value,
“gteamPict”: $w(“#uploadButton2”).value,
“hTeampict”: $w(“#uploadButton4”).value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.insert(“MATCH_SUMMARY”, gteamname)
}
This code work perfectly, it update datas entry in DB1(with SUBMIT connect dataset) and save all fields onclick event into DB2.
But in the same webpage I have a similar code doing the same thing for a other button, but the SUBMIT connect to dataset to DB1 doesn’t work this time. DB2 onclick event working !? I don’t understand why (it work with the other button and onclick event describe upper) )? If it could work in this way you could ignore my previous post and it would be really more simple! Here’s the second CODE :
export function button54_click_1(event, $w) {
let playername = {
“player”: $w(“#input30”).value,
“position”: $w(“#dropdown1”).value,
};
console.log(“person to be saved” + JSON.stringify(playername));
wixData.insert(“STATS”, playername)
}
Thank you in advance to look at what’s wrong with… -Ronny
URL : https://www.cibledetection.com/players-name-import-position-home
HI SHLOMI ! I found the problem… There was required fields blocking submit action!!! So the question is there’s a code to ignore required fields for this submit button ?
Hey Ron,
Glad to hear!
Please see the different available options here: https://www.wix.com/code/reference/$w.FormElement.html
Shlomi
HI Shlomi, Thanks for options, I read fast but it seem’s to be only for appling a required field condition! What about ignoring required field condition with button onclick event ?..
Also! Now I need to refresh my tables when I submit data in my second DB with the onclick event, without refreshing page !? Any trick do do this ?
thanks!
Ron,
http://www.wix.com/code/reference/wix-dataset.html#refresh
And try
$w(“#myElement”).required = false;
Shlomi
Mmmmmm!
About refresh, page code notifications say it apply refresh to DB, but datas doesn’t appear in table and input boxes !? Is it possible the refresh action is made before submission !? If yes can we apply a ‘‘then’’ function, I have tried but it display errors when trying to do that!
Required = false working perfectly …Thank you Shlomi!
GOT IT ! (refresh)
export function button56_click(event, $w) {
let goaliename = {
“goalieRecords”: $w(“#input30”).value,
“gposition”: $w(“#dropdown1”).value,
“goaliePict”: $w(“#uploadButton8”).value,
};
console.log("person to be saved" + JSON.stringify(goaliename));
wixData.insert("Stats", goaliename)
//$w("#input26").required = false;
//$w("#input23").required = false;
.then( () => {
$w(“#dataset6”).refresh()
console.log(“Done refreshing the dataset”);
} );
}
Yay!!! great job!
Hi Shlomi, Trying a then function to refresh page after IMPORT… I think it is brackets issue, tried different configurations of brackets without success. What’s wrong!?
Hi Ron,
couldn’t find the exact page you were referring to, maybe create a simple example that simplifies your question?
you can not just drop .then(…) anywhere in the code, just after asynchronous execution in which you want to add a callback at the end of the execution.
please have a look at Javascript ‘Promise’ and async await which you can use here
or in this case since you want something to happen once multiple promises are delivered, try this:
good luck!
Shlomi
Hi Shlomi… Thank you! That helped me a lot to perform… I have a other problem according second DB saving onclick event… The pictures values don’t want to save! Any idea ? Here’s my code and URL link!
Thanks in advance!
export function button12_click(event, $w) {
let gteamname = {
“gteamName”: $w(“#input26”).value,
“hteamName”: $w(“#input23”).value,
“gteamPict”: $w(“#uploadButton2”).value,
“hTeampict”: $w(“#uploadButton4”).value,
“title”: $w(“#input24”).value,
“gameDate”: $w(“#datePicker1”).value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.insert(“MATCH_SUMMARY”, gteamname)
}
Url :https://www.cibledetection.com/players-name-import-position-home
Hi Shlomi…Temporary, To try to solve my previous picture saving problem I have reverse DB saving. So I submit all data in the first DB, in this way, I only need to save two text values into second one. The problem is the code working perfectly with insert function but do not work at all with update function !?
export function button12_click(event, $w) {
let gteamname = {
“guestTeam”: $w(“#input26”).value,
“team”: $w(“#input23”).value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.update(“PLAYERS_NAME_IMPORT”, gteamname)
.then( () => {
$w(“#dataset5”).refresh()
console.log(“Done refreshing the dataset”);
} );
Hi Ron,
the update operation will replace the existing record with the new one you provide, so please also copy all of the existing fields you want to preserve
please read further here: http://www.wix.com/code/reference/wix-data.html#update
Shlomi
‘‘The update operation will replace the existing record with the new one you provide’’ : This operation doesn’t work ! I understand the fact about preserving known values data fields I want to preserve with this reference! But what about updating with NEW User entries ? And what about Picture submission onclick event issue !?
Hi Ron,
update is made to an existing record in the db with the same ‘ID’ you provide.
for image upload specifically please have a look here: Velo Tutorial: Using the Upload Button with Code | Help Center | Wix.com
Shlomi
Hi Shlomi… Thank again for your help… So why the following code is not working ? It’s build with the same structure of reference you shared, but it is for unknown values (User values) !?
export function button12_click(event, $w) {
let gteamname = {
“guestTeam”: $w(“#input26”).value,
“team”: $w(“#input23”).value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.update(“PLAYERS_NAME_IMPORT”, gteamname)
.then( () => {
$w(“#dataset5”).refresh()
console.log(“Done refreshing the dataset”);
} );
Hi Ron,
in the object gteamname , you are not using the ID column of the column you want to be updated. they key of the existing record in the db is missing,
if it is indeed an update operation, i assume you have the db record in current context, for example you are using a dynamic page with dataset and you can use http://www.wix.com/code/reference/wix-dataset.html#getCurrentItem - please have a look at the example here, specifically for the ‘_id’ property
Shlomi
Sorry Shlomi But There’s a Bug for Sure, since 3 days I’m testing and trying :
This code IS WORKING with INSERT :
export function button12_click(event, $w) {
let gteamname = {
“guestTeam”: $w(“#input26”).value,
“team”: $w(“#input23”).value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.insert(“PLAYERS_NAME_IMPORT”, gteamname)
.then(() => {
$w(“#dataset5”).refresh()
console.log(“Done refreshing the dataset”);
});
}
====================================================
SAME CODE Is NOT WORKING with UPDATE function :
export function button12_click(event, $w) {
let gteamname = {
“guestTeam”: $w(“#input26”).value,
“team”: $w(“#input23”).value,
};
console.log(“person to be saved” + JSON.stringify(gteamname));
wixData.update(“PLAYERS_NAME_IMPORT”, gteamname)
.then(() => {
$w(“#dataset5”).refresh()
console.log(“Done refreshing the dataset”);
});
}
Hi Ron,
in the example above
let gteamname = {
“guestTeam”: $w(" #input26 ").value,
“team”: $w(" #input23 ").value };
wixData.update(“PLAYERS_NAME_IMPORT”, gteamname)
}
what record do you expect to be updated? you are missing the unique record you think you mean
Shlomi
Afffffff! I never suspected that we absolutely need to specify the ID line to be update… But now it’s working, but I thought it will only update specified fields values !? Is it possible ?
As you know I’m learning coding, it’s not easy, thanks for your help!
I’m facing a other challenge !
Now I want to do a similar thing but I don’t know the field ID yet because this line is not existing ( submission button is link connect to NEW). I would like to copy same data for 2 existings fields in the previous recorded lines, at each new line creation !? In fact I want to duplicate and keep these 2 fields value at each NEW Line creation. I suspected you will tell me to Use a after insert hook, but the way to code hook is little different than in a page. I tried without success…