Display repeater text based on boolean value

Hello,

I am working on the review/comments feature of my website and I would like to know how to display the text “I recommend” in the repeater based on the value from the dataset.

There is a form that allows customers to input this information into the dataset. For this, I used radio buttons “I recommend” = True ; " I do not recommend" = False. The field type in the dataset is set to boolean.

The problem is that when someone leaves a review, the value in the dataset does not populate as “True” or “False.” Instead, there is a weird code and I have to manually convert it so the correct value shows on the repeater. In the meantime, “I recommend” displays on the repeater regardless of whether the customer recommends.

How can I get the radio value to populate into the boolean field correctly? I am open to suggestions.

The code I am using is below:

$w.onReady( function () {
$w(‘#dataset1’).onReady( () => {
$w(‘#repeater1’).forEachItem( ($w, itemData, index) => {
if (itemData.recommended){
$w(‘#recommendation’).text = “I recommend this product.”;
}
else {
$w(‘#recommendation’).text = " ";
}
} );
} );
} );

Thank you for all your help!

Hi there :wave:t2: Not sure if this is the issue, but try changing the radio button values of “True” and False" to " true " and " false ", all lower-case.
If this doesn’t solve the problem, then we could fix it using the setFieldValue function.

For your code issue, replace this line:

if (itemData.recommended) {

With this:

if (itemData.recommended === true) {

and it should work as you intend.

Good luck!

Hi there …

This question has been asked hundreds on times on the forum, please search the forum for similar questions.

Changing the values to lower case did not work but the code did! Thank you so much! I looked everywhere and I still don’t know how to edit codes. Really hit or miss. Anyways, thanks again! :smile: