top of page

Forum Posts

Blai
Mar 04, 2019
In Coding with Velo
Hey community! I'm trying to work with some repeaters, but I'm not sure if I should use any other system. What I want to do is to be able to select different items on a modify them, just the ones that are selected. I need to remove the selected items from the database and insert them into a new one. The code that I have now is this one: import wixData from 'wix-data'; import wixUsers from 'wix-users'; $w.onReady(function () { $w("#accept").onClick( (event) => { let seleccionado = $w('#seleccionado').value === true; let clickedItem = $w("#dataset1").getCurrentItem(seleccionado)['_id']; $w("#applicants").forItems(clickedItem) let saveApplication = { "name": $w('#dataset1').getCurrentItem(seleccionado)['name'], "email": $w('#dataset1').getCurrentItem(seleccionado)['email'], "company": $w('#dataset1').getCurrentItem(seleccionado)['company'] }; wixData.insert("Accepted", saveApplication) .then( (results) => { let item = results; //see item below } ) .then( () => { $w("#dataset1").remove(seleccionado) .then( () => { console.log("Done removing current item"); } ) }); }); $w("#decline").onClick( () => { if($w('#seleccionado').checked === true){ let clickedItemData = $w("#dataset1").getCurrentItem(); let saveApplication = { "name": $w('#dataset1').getCurrentItem()['name'], "email": $w('#dataset1').getCurrentItem()['email'], "company": $w('#dataset1').getCurrentItem()['company'] }; wixData.insert("declined", saveApplication) .then( (results) => { let item = results; //see item below } ) .then( () => { $w("#dataset1").remove(clickedItemData) .then( () => { console.log("Done removing current item"); } ) }); } }); But if I have 5 applications (items on the repeater), they only save and remove the last one uploaded, not the selected ones. What should I do?:( Thanks!!
Select items on a Repeater and modify them content media
0
0
600
Blai
Sep 01, 2018
In Coding with Velo
Hey! I have a problem: when the users sign up to my website they are saved as new Members but their information is not saved to the collection.... What should I do? Here's the code: import wixUsers from 'wix-users'; import wixData from 'wix-data'; export function button1_click() { let userId; let userEmail; // prompt the user to log in wixUsers.promptLogin( {"mode": "login"} ) .then( (user) => { userId = user.id; return user.getEmail(); } ) .then( (email) => { // check if there is an item for the user in the collection userEmail = email; return wixData.query("Company") .eq("_id", userId) .find(); } ) .then( (results) => { // if an item for the user is not found if (results.items.length === 0) { // create an item const toInsert = { "_id": userId, "email": userEmail }; // add the item to the collection wixData.insert("Company", toInsert) .catch( (err) => { console.log(err); } ); } } ) .catch( (err) => { console.log(err); } ); } Thanks!
0
9
193
Blai
Aug 15, 2018
In Coding with Velo
Hey! Do you know how could I custom a registration form + update the information on the database? I tried with the Wix function (connecting each field to the database and to submit) but its not working. Right now I have this: import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixData from 'wix-data'; $w.onReady(function(){ $w('#register').onClick(function (){ let updates = { "companyName": $w("#companyname").value, "email": $w("#email").value, "password": $w("#password").value, "title": $w("#name").value, "_id": wixUsers.currentUser.id }; wixData.save("Company", updates) .then( (results) => { wixLocation.to("/welcome"); } ) .catch( (err) => { let errorMsg = err; } ); let email = $w('#email').value; let password = $w('#password').value; wixUsers.register(email,password,{ "contactInfo": { "title": $w('#name').value, "companyName": $w('#companyname').value, } }) .then( ()=>{ wixLocation.to('/welcome'); }) }) }) But I also tried this: import wixUsers from 'wix-users'; import wixLocation from 'wix-location'; import wixData from 'wix-data'; $w.onReady(function(){ $w('#register').onClick(function (){ let email = $w('#email').value; let password = $w('#password').value; wixUsers.register(email,password,{ "contactInfo": { "title": $w('#name').value, "companyName": $w('#companyname').value, } }) .then( ()=>{ wixLocation.to('/welcome'); }) }) }) export function register_click(event, $w) { let updates = { "companyName": $w("#companyname").value, "email": $w("#email").value, "password": $w("#password").value, "title": $w("#name").value, "_id": wixUsers.currentUser.id }; let req1 = $w("#companyname").valid; let req2 = $w("#email").valid; let req3 = $w("#password").valid; let req4 = $w("#name").valid; if (req1 === false || req2 === false || req3 === false || req4 === false) $w("#errorText").show(); else {wixData.save("Company", updates) .then(() => { //go to welcome page wixLocation.to("/welcome"); }) .catch( (err) => { console.log(err); } ); }} Because I read somewhere that they had problems with fields that had the required option. Thanks!!
1
2
1k
Blai
Aug 10, 2018
In Coding with Velo
Hey everybody! Well my question is just the title: How can I collapse a text if that field is empty in the database? For example: I'm trying to put 3 languages. If the second and third are not filled I want that the dynamic page with their information (like a profile) just shows 1 language without having a big space under that (because the second and third languages are there empty). Thanks! (I tried a query, to getCurrentItem and something else but I couldnt manage to do it)
0
15
2k
Blai
Aug 06, 2018
In Coding with Velo
Hey everybody, the code in the example is so confusing. I tried to do it but when I copy the code there are some things wrong: it appears problems with unexpected tokens (. for example). It also says that I havent defined an approvaltoken but I dont know how tokens works and in that example is not telling me anything, so its not really useful to copy the code if there are lots of parts that you need help and its not solving it...:(
0
4
102
Blai
Jul 31, 2018
In Coding with Velo
Hey! I used a Yoav tutorial to create a review system that its not working perfectly. I have 2 problems: 1- The Review stats database is not being uploaded (IDK why). 2- The users can submit just 1 review, after that all the reviews are upload but not updated to the different databases. The lightbox is also not closing at the end. Tutorial: https://www.wix.com/code/home/forum/wix-tips-and-updates/example-store-reviews-rating What should I do? Thank you very much! PS: My code on the light box (the main problem for updating statistics): import wixWindow from 'wix-window'; import wixData from 'wix-data'; let companyId; let rated = false; let reviewRating; $w.onReady(function () { companyId = wixWindow.lightbox.getContext().companyId; initStars(); $w('#SubmitReviews').onBeforeSave(() => { console.log('beforeSave'); if (!rated) { $w('#rateError').show(); return Promise.reject(); } $w('#SubmitReviews').setFieldValues({ companyId, rating: reviewRating || 0, recommends: $w('#radioGroup1').value }); }); $w('#SubmitReviews').onAfterSave(async () => { await updateStatistics($w('#radioGroup1').value); wixWindow.lightbox.close(); }); }); const blueStars = ["starBlue1", "starBlue2", "starBlue3", "starBlue4", "starBlue5"]; const grayStars = ["starGray1", "starGray2", "starGray3", "starGray4", "starGray5"]; function initStars() { for (let i = 0; i < grayStars.length; i++) { const numberOfStar = i+1; const grayStar = $w(`#starGray${numberOfStar}`) const blueStar = $w(`#starBlue${numberOfStar}`) grayStar.onMouseIn((event) => { fillStars(numberOfStar); }); blueStar.onMouseIn((event) => { fillStars(numberOfStar); rated = true; reviewRating = numberOfStar; }); } } function fillStars(numberOfStars) { $w('#rateError').hide(); for (var i = 0; i < blueStars.length; i++) { const numberOfStar = i+1; let star = $w('#'+blueStars[i]); if (numberOfStar <= numberOfStars) { star.show(); } else { star.hide(); } } } async function updateStatistics(isRecommended) { let stats = await wixData.get('ReviewStats', companyId); if (stats) { stats.rating += reviewRating; stats.count += 1; stats.recommended += isRecommended?1:0 return wixData.update('ReviewStats', stats) } stats = { _id: companyId, rating: reviewRating, count: 1, recommended: isRecommended?1:0 }; return wixData.insert('ReviewStats', stats) }
0
3
67
Blai
Jul 31, 2018
In Coding with Velo
Hey! I have 4 inputs required (using the wix function to connect inputs with the database): email, password, company name and profile image. When the user clicks submit, the form is submited instead of showing the failure message and staying on the page. What should I do? Thanks! PS: The submit action is also via WIX functions, not with code.
1
12
506
Blai
Jul 31, 2018
In Coding with Velo
Hey! I have one button connected to delete information of the database but then the user stay in that page and it's not logging out. Should I connect the button to the delete function with code or can I use the Wix function and also log out the user? How could I do that? Thanks!!!
0
7
77
Blai
Jul 22, 2018
In Coding with Velo
Hey! I have some forms that ask for an image to be submited. I said the image input is mandatory, but is not turning red if you are not uploading an image, so the users get confused. What should I do? Thank you!
0
4
90

Blai

More actions
bottom of page