top of page

Forum Comments

Build an Alert Component Using Custom Elements
In Tips, Tutorials, Examples
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Salman2301
Velo Certified
Velo Certified
Jul 25, 2020
There is two way to do it I prefer the wixData.update as it feels reliable // SOLUTION 1: /*  We can get the Instructor details from the dynamic dataset and   Update the collection from wixData update   If you wanna update to different database you will need to query the database  to get the _id before update the value */ import wixData from "wix-data"; $w.onReady(function () {   $w("#dynamicDataset").onReady(() => {     $w("#dataset5").onReady(() => {       saveQuoteData();     });   }); }); async function saveQuoteData() { const courses = $w("#dynamicDataset").getCurrentItem(); const instructor = courses.instructorName; const instructorName = instructor.title;   instructor.quote = $w('#iptQuote').value;   wixData.update("Instructors", instructor)   .then((updated)=>{     console.log("Updated the 'Instructors' database :", updated);   })   .catch(console.error) } // SOLUTION 2: /*   Filter the dataset and use setFieldvalue and Save to update the quote on page load   You can also call the saveQuoteData function on a button click */ import wixData from "wix-data"; $w.onReady(function () {   $w("#dynamicDataset").onReady(() => {     $w("#dataset5").onReady(() => {       saveQuoteData();     });   }); }); async function saveQuoteData() { const courses = $w("#dynamicDataset").getCurrentItem(); const instructorName = courses.instructorName.title; const filter = wixData.filter().eq("title", instructorName); await $w("#dataset5").setFilter(filter); // filtering the dataset will update the current Index   console.log("Updating Quote") await $w("#dataset5").setFieldValue("quote", $w('#iptQuote').value); await $w("#dataset5").save(); }
1
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Salman2301
Velo Certified
Velo Certified
Jul 11, 2020
Happy to help and thank you for the support :)
0
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Salman2301
Velo Certified
Velo Certified
Jul 11, 2020
/* It's better to use a reference field, to connect the Collection databas with the product database Once you create a column and set the data type to reference in the Product database and point to Collection database Then you can use database UI to search for the collection and select the collection for each product For now we can't use repeater inside of repeater, So, your's is the only solution to use a fixed Number elements in your case it's five But you can attach the table inside of the repater to display multiple prooduct If you done it right you don't need any code to connect the table to the database */ import wixData from 'wix-data'; var ItemLength $w.onReady(function () { wixData.query("Collection")     .find()     .then((res) => { let Item = res.items ItemLength = res.items.length wixData.query("Products")         .find()         .then((results) => { let product = results.items; $w("#repeater1").onItemReady(($item, itemData, index) => { for (var i = ItemLength - 1; i >= 0; i = i - 1) { const currTitle = Item[i].title; const iteration = ( index * 4 ) + i; console.log("i = " + i); console.log("index = " + index); console.log('--------------------'); if (itemData.title === currTitle) { $item("#TXTtype1").text = product[iteration].type; $item("#IMGtype1").src = product[iteration].image; console.log("Output-Index1 = " + index) $item("#TXTtype2").text = product[iteration + 1].type; $item("#IMGtype2").src = product[iteration + 1].image; console.log("Output-Index2 = " + index) $item("#TXTtype3").text = product[iteration + 2].type; $item("#IMGtype3").src = product[iteration + 2].image; console.log("Output-Index3 = " + index) $item("#TXTtype4").text = product[iteration + 3].type; $item("#IMGtype4").src = product[iteration + 3].image; console.log("Output-Index4 = " + index) $item("#TXTtype5").text = product[iteration + 4].type; $item("#IMGtype5").src = product[iteration + 4].image; console.log("Output-Index5 = " + index)               } console.log('--------------------')             }           });         });     }); });
1
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Salman2301
Velo Certified
Velo Certified
Jul 04, 2020
/*     Hey dima, Hope you are doing well     i think the best way IMO is to use external lib     to search the word, I have used fuzzy search before     I will recommend that     https://www.npmjs.com/package/fuzzy-search     I have refactor the code and you just compute onetime and store the value     e.g:     const sliceWord = mySearchWord.slice(0, searchWordLength);     and use `let` instead of `var`     and don't use `PARAMS` */ export function button1_click() { SEARCH(); } function SEARCH() { let wordCounter = 0; let myText = $w("#TXTinput").text; $w("#TXToutput").text = ""; let searchValue = $w("#input1").value; //.toLowerCase(); let searchWordLength = searchValue.length; let searchWords = myText.split(" "); let searchWords1 = []; let searchWords2 = []; let searchWords3 = []; $w("#wordLength").value = searchWordLength; console.log(searchWords); for (let i = 0; i < searchWords.length; i++) { let mySearchWord = searchWords[i]; console.log(mySearchWord); const sliceWord = mySearchWord.slice(0, searchWordLength); const charCodeAt = mySearchWord.charCodeAt(searchWordLength + 1); const sliveWord1 = mySearchWord.slice(1, searchWordLength + 1); const charCode0 = mySearchWord.charCodeAt(0); if (sliceWord === searchValue || sliceWord === searchValue.toLowerCase()) { console.log("YES-1"); if (charCodeAt >= 65 && charCodeAt <= 90) {       } else if (charCodeAt >= 98 && charCodeAt <= 122) {       } else if (charCodeAt >= 192 && charCodeAt <= 255) {       } else { console.log("FOUND-1"); searchWords1.push(mySearchWord), wordCounter++;       }     } if (sliveWord1 == searchValue || sliveWord1 == searchValue.toLowerCase()) { console.log("YES-2"); console.log(mySearchWord.charCodeAt(1)); if (charCode0 >= 65 && charCode0 <= 90) { console.log("1");       } else if (charCode0 >= 98 && charCode0 <= 122) { console.log("2");       } else if (charCode0 >= 192 && charCode0 <= 255) { console.log("3");       } else { console.log("FOUND-2"), searchWords2.push(mySearchWord), wordCounter++;       }     }   } searchWords3 = searchWords1 + searchWords2; console.log("---- 1 ----"); console.log(searchWords1); console.log("---- 2 ----"); console.log(searchWords2); console.log("---- 3 ----"); console.log(searchWords3); $w("#OUTPUTfoundterms").value = wordCounter; $w("#TXTresults").text = searchWords3; $w("#TXToutput").text = searchWords.toString(); }
1
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo
Code Review Friday: (Let's Improve your code, ask Corvid Master)
In Coding with Velo

Salman2301

Velo Certified
Content Creator
Velo Expert
+4
More actions
bottom of page