[SOLVED] I cannot get the values of my Text Elements

Hey!

I don’t know why but I cannot get the values of the Text Elements inside my Repeater.

I am trying to get the value of $w(‘#firstName’) and $w ( ‘#emailAdd’ ) - both are connected to a Dataset. But what I am getting are the default values of the Text Element: “Heading5”.

What am I doing wrong?

Here is my code:

$w.onReady(function () {
    $w('#btnApprove').onClick(function () {
        let firstName = $w('#firstName').text;
        let emailAdd = $w('#emailAdd').text; 
        console.log(emailAdd);
        console.log(firstName);
        /*sendEmailToContact(emailAdd)
        .then(() => {       
            wixLocation.to('/blank-2');
        })
        .catch((error) => {
            console.log(error);
                        //wixLocation.to('/application');
        });*/
    });
});

Below are the screenshots of my code and my Logs.

Please add your code as → CODE in a nice looking CODE-BLOCK and not as → IMAGE !!!

Hi @russian-dima , below is the code:

$w.onReady(function () {
    $w('#btnApprove').onClick(function () {
        let firstName = $w('#firstName').text;
        let emailAdd = $w('#emailAdd').text; 
        console.log(emailAdd);
        console.log(firstName);
        /*sendEmailToContact(emailAdd)
        .then(() => {       
            wixLocation.to('/blank-2');
        })
        .catch((error) => {
            console.log(error);
                        //wixLocation.to('/application');
        });*/
    });
});

First of all → why you do not use an inputfield instead of a text-field?
Second, if you use a DATASET…

$w.onReady(()=>{
	$w('#YourDatasetIDhere').onReady(()=>{
		//the rest of your code here....
		//the rest of your code here....
		//the rest of your code here....
		//the rest of your code here....
	});
});

Let’s say you have done till here everything right and did use an INPUT_FIELD instead of a TEXTFIELD…

$w.onReady(()=>{
	$w('#YourDatasetIDhere').onReady(()=>{
		$w('#btnApprove').onClick(function(){
			let firstName=$w('#inpFirstName').value;
			console.log("Firstname: ", firstName);
			let emailAdd=$w('#inpEmailAdd').text;
			console.log("Email: ", emailAdd);
	});
});

→ inp ← stands for INPUT

What do you get in your console now?

Wow! I did not know about the $w ( ‘#YourDatasetIDhere’ ). onReady (() => { code. Thank you for pointing that out!
I already solved my problem!

Here is my complete code:

$w.onReady(function () {
   $w('#dataset1').onReady( () => {
       $w('#btnApprove').onClick((event) => {
           let $item = $w.at(event.context);
           let emailAdd = $item("#emailAdd").text;
           let firstName = $item("#firstName").text;
           console.log(emailAdd);
           console.log(firstName);
       }); 

       $w('#btnDisapprove').onClick((event) => {
           let $item = $w.at(event.context);
           let emailAdd = $item("#emailAdd").text;
           let firstName = $item("#firstName").text;
           console.log(emailAdd);
           console.log(firstName);
       });
   });
});

Now, I can correctly get the values of any selected repeater record.

Thanks a lot!

Looks good!