Hi Yisrael,
Thank you for taking a look at the mess I am in ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/google_classic/slight_smile.png?v=12)
Like I said I am new to coding but generally a fast learner.
Maybe if I explain better you can help.
What I have done so far is take the input of two date-pickers from the home page subtracted the
days difference and populated a drop-down with the result.
All the data from the homepage is moved to the page in question and populates another set of date-pickers and another drop-down (not in the repeater).
The repeater is connected to a “cars” database and shows a list of cars (rentals),and there is a text element (in the repeater) that i want to display the price of the amount of days that is in the drop-down.
The drop-down contains a number, and in the database i cant use a number for a field id,
so i made another database "days"with a number field “int” and a text field “str”.
Now when I query the database for number “1” I get “one” and so on,witch are the data-field ID’s of the prices (one two three…twentyone) of my cars database.
That’s why i want to insert the value of the query to the $w(‘#repeater1’).onItemReady every time the value of the drop-down changes.
$w(‘#repeater1’).onItemReady( ($item, itemData, index) => {
$item(“#text51”).text = itemData. two ; <—This two as is displays on “#text51” the price of 2days. If I try to use a variable instead of directly typing in “two” i get errors.
Is there a way around this? I have been reading almost all the posts for something relevant for days
but looks like i hit a dead end. Am I going at this the wrong way?
Her is the code of the whole page so you get a better idea of what is going on.Most of it is inspired from posts you made helping others ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/google_classic/slight_smile.png?v=12)
// For full API documentation, including code examples, visit Velo API Reference - Wix.com
//////////////////////////////////////////
//Set minimun Date for second datepicker//
//////////////////////////////////////////
export function datePicker1_change(event, $w) {
let date1 = $w(“#datePicker1”).value;
$w(“#datePicker2”).minDate = date1
$w(“#datePicker2”).value = date1
console.log($w(“#datePicker1”).value);
}
//////////////////////////////////////
// display date2 - date1 difference //
//////////////////////////////////////
export function datePicker2_change(event, $w) {
let date1 = $w(“#datePicker1”).value;
let date2 = $w(“#datePicker2”).value;
let diff = (date_diff_indays(date1, date2)) ;
$w(“#dropdown5”).value = diff ;
// console.log(date_diff_indays(date1, date2));
}
//////////////////////////////////////////
//datepicker1 - datepicker2 calculations//
//////////////////////////////////////////
export function date_diff_indays(date1, date2) {
let dt1 = new Date(date1);
let dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
}
//////////////////////////////////////
//populate setings from preveus page//
//////////////////////////////////////
import {local} from ‘wix-storage’;
import wixData from ‘wix-data’;
$w.onReady( function () {
var date1new = new Date(local.getItem(“date1old”))
var date2new = new Date(local.getItem(“date2old”))
var sameWord = local.getItem(“searchWord”);
$w("#datePicker1").value = date1new;
$w("#datePicker2").value = date2new;
$w("#dropdown5").value = sameWord;
$w(‘#dataset1’).onReady( function () {
search();
});
console.log( date1new);
console.log( sameWord );
} );
//////////////////////////////////////////////////////////
//pic the days field (str) based on number of #dropdown5//
//////////////////////////////////////////////////////////
export function button4_click() {
search();
}
function search() {
wixData.query(“days”)
.eq(“int”, $w(“#dropdown5”).value)
.find()
.then( (results) => {
let items = results.items;
let days = items[0].str;
console.log(days);
/////////////////////////// Ok till here ///////////////////
$w(‘#repeater1’).onItemReady( ($item, itemData, index) => {
$item(“#text51”).text = itemData.two;
console.log();
});
});
}
Thank you
Aris