top of page

Forum Comments

Interact with container/repeaters
In Coding with Velo
jahir_salgado
May 31, 2023
Hola, Code-Ninja! 😁 Happy to see you again, sorry for the late response! It really surprises me how creative you can be with this kind of situations Before starting, I'd say that I liked too much your idea of doing the calculation and then placing that result in the database. Something like: { Item1 Calculates total of Item1 Saves that total in the row of Item1 } Loop { Item2 Calculates total of Item2 Saves that total in the row of Item2 } Loop... Until it finishes all items in list 1) You are working on a dynamic or non-dynamic page? It is a dynamic page 2) Your repeater is placed on a dynamic or non-dynamic page? It is a dynamic page 3) Your repeater is connected with your database trough a dataset? Yes, it is 4) The name element inside your repeater is connected to your dataset (inside property-panel) Yes, they are 5) Your image-element inside your repeater is connected to your dataset (inside property-panel). Yes, it is 6) Your FREE-TEXT is connected to anything. --> of course without any functionality, yet. That's right Where is your code? Okay, I'll show you my code for calculating the result I want (you'll know more about how I calculate this and the explanation of it in the next questions): export function columnStrip3_viewportEnter(event) { let total; let filter = wixData.filter(); total = "Item1"; if (total){ filter = filter.eq("material","Item1"); } wixData.aggregate("Inventario") .filter(filter) .sum("cantidad", "total") .run() .then ((result) => { var income = result.items[0].total $w('#total').text = income.toLocaleString() }) } (I know, I'm not the best at coding, but this is what I do and it works 😅) • The database "Inventario" is where all movements are saved (items in, items out) • This code gives me only the total of Item1 available (and shows it in $w('#total'). What I want is to save that result (in column "Stock", we'll see it later) and then, automatically, loop to Item2, Item3... -What to calculate? In a nutshell, the total of items in an inventory. For example, (there were +3 Items1, and -1 Item1, so the result I want to save is 2, that is the total of Item1 I have available) -Where to get data from for calculation ? Okay, I've got 2 databases. In the first one you can see the movements (items in, items out) of my materials, this is the database "Inventario": (as you can see, here I save the movements) Okay, then The second database is the one where all my items are saved: This is "Item1", "Item2", "Item3"... The are ordered from A to Z This database is also the one that is connected to the repeater. So, I the empty column, named "Stock", I want to save there the total available, let's use the previous example, there were +3 Items1, and -1 Item1, so the result I want to save is 2, that number (number two) is the one that has to be saved in the column "Stock", when it finishes saving, so it goes for Item2, Item3... 1) When exactly starts your process? User clicks on a button? Where this button can be found --> inside repeater / outside-repeater? I'd like the trigger to be a "viewportEnter", outside-repeater 2) Ok, we know you want to loop trough all of the repeater, items and doing some calculations? Well, yeah, every item has its own calculation (the result of Item1, Item2...) 3) We also know, that some of your elements are connected with your dataset and some not. That's right. What I'm thinking (using your point of view that I liked too much) is to connect the no connected elements ("free text") to the "Stock", that is the result that has to be shown 4) How does look your database? It is already shown 5) How does look like your current working/not working code? It is already shown Thank you so much for your time and answer!
Content media
[SOLVED] Getting the first day of month
In Coding with Velo
[SOLVED] Validate data
In Coding with Velo
jahir_salgado
Sep 06, 2022
Best Answer
Hi everyone, again Little by little I found ways to achieve what I wanted. What I achieved: 1. To validate if the inputs are not empty, all of them must be filled 2. To validate their "type" (if the input requests numbers, it won't be saved if it is text) 3. I want the inputs that were filled incorrectly or left empty to change to their Error Mode 4. If there is any error, the code won't save the information and an Error Message will appear 5. If everything is OK, a Success message will appear, then it saves the information 6. Finally, after the success message, all the inputs delete the info they have and the counter ($w('#text13')) refreshes (a loop, in a nutshell) PLEASE, IF YOU WANT TO ACHIEVE THIS TOO (BUT DON'T GET MY CODE) COMMENT THIS AND I'LL TELL WHAT I DID So, here it is my final code: import wixData from 'wix-data'; $w('#dropdown2').required; $w('#dropdown1').required; $w('#input2').required; $w("#input2").inputType = "number"; $w('#datePicker1').required; $w("#input2").onKeyPress(event => { setTimeout(() => {validateInput();}, 10) }) function validateInput(){ let value = $w("#input2").value; if (/[a-z]/.test(value.toLowerCase())){ $w("#input2").value = ""; } } $w.onReady(function () { wixData.query("Entradas") .count() .then ((result) => { $w('#folio').text = result.toString() }) }); export function dropdown2_change(event) { $w('#dropdown2').style.backgroundColor = "#BCC8D9"; wixData.query("Entradas") .count() .then ((result) => { $w('#folio').text = result.toString() }) } export function dropdown1_change(event) { $w('#dropdown1').style.backgroundColor = "#BCC8D9"; wixData.query("Entradas") .count() .then ((result) => { $w('#folio').text = result.toString() }) } export function input2_change(event) { $w('#input2').style.backgroundColor = "#BCC8D9"; wixData.query("Entradas") .count() .then ((result) => { $w('#folio').text = result.toString() }) } export function datePicker1_change(event) { wixData.query("Entradas") .count() .then ((result) => { $w('#folio').text = result.toString() }) } export function button2_click(event) { $w("#input2").onKeyPress(event => { setTimeout(() => {validateInput();}, 10) }) function validateInput(){ let value = $w("#input2").value; if (/[a-z]/.test(value.toLowerCase())){ $w("#input2").value = ""; } } $w('#dropdown2').required; $w('#dropdown1').required; $w('#input2').required; $w('#datePicker1').required; if ($w('#dropdown2').value === ""){ $w('#Error').show(); $w('#message').hide(); $w('#dropdown2').style.backgroundColor = "#C23B22"; console.error(); } if ($w('#dropdown1').value === ""){ $w('#Error').show(); $w('#message').hide(); $w('#dropdown1').style.backgroundColor = "#C23B22"; console.error(); } if ($w('#input2').value === ""){ $w('#Error').show(); $w('#message').hide(); $w('#input2').style.backgroundColor = "#C23B22"; console.error(); } if ($w('#input2').value === "text"){ $w('#Error').show(); $w('#message').hide(); $w('#input2').style.backgroundColor = "#C23B22"; console.error(); } if ($w('#datePicker1').value === null){ $w('#Error').show(); $w('#message').hide(); console.error(); } if ($w('#dropdown2').valid) { if ($w('#dropdown1').valid) { if ($w('#input2').valid) { if ($w('#datePicker1').valid) { $w('#message').show(); $w('#Error').hide(); const cant = $w('#input2').value const pre = $w('#input3').value var precio = cant * pre let x = parseFloat(precio).toFixed(2); $w('#input4').value = x.toString() let folio = $w('#folio').text let escuela = $w('#dropdown1').value let dulce = $w('#dropdown2').value let fecha = $w('#datePicker1').value let cantidad = Number($w('#input2').value) let inversion = Number(x) let s = "+" let si = "-$" let toInsert = { "title": folio, "escuela": escuela, "dulce": dulce, "fecha": fecha, "s": s, "cantidad": Number(cantidad), "si": si, "inver": Number(inversion) }; wixData.insert("Entradas", toInsert) .then((results) => { console.log(results); }) $w('#dropdown2').value = ""; $w('#dropdown1').value = ""; $w('#input2').value = ""; $w('#datePicker1').value = null; $w('#dropdown2').resetValidityIndication(); $w('#dropdown1').resetValidityIndication(); $w('#input2').resetValidityIndication(); $w('#datePicker1').resetValidityIndication(); wixData.query("Entradas") .count() .then ((result) => { $w('#folio').text = result.toString() }) .catch((err) => { console.log(err); }); } } } } }
1
0
[SOLVED] Value saved as "text" instead of "number" type
In Coding with Velo
Date alerts
In Coding with Velo

jahir_salgado

More actions
bottom of page