Using a wix dataset field as a conditional to display certain text.

Hi! I am new to wix code and am looking to create a CV website that displays “Start Month”, “Start Year”, “–”, “End Month”, “End Year”. So far I got this working. The problem is when there is no end date because the activity is still going on. In this case, I would like to show the text “Present” instead of “End Month”, “End Year”.

I have added a boolean column to the dataset that allows the editor to enable if they are still involved with the activity. But how can I create a conditional statement that will show certain text if the box is checked and different text if the box is not checked? Seems like this would be simple, but I could not find any examples. Also just for reference, the text I am displaying is in a repeater on the site.

Thank you in advance!

Ryan

Sam (Wix Mod) had a good example for this in an old post.

Because you mentioned you’re on a dynamic page, I assume your repeater is connected to a dataset. This makes things a little more complicated because you have to wait for the dataset to load. If you would use onItemReady() to set your field values, the dataset would just overwrite them.
You want to do something like this:

$w.onReady(function () {
    $w('#dataset1').onReady( () => {
      $w('#repeater1').forEachItem( ($w, itemData, index) => {
          if(itemData.boolField){
              $w('#boolText').text = "Yes Ma'am!";
          }
          else {
              $w('#boolText').text = "No way Jose!";
          }
      } );
  } );
} );

Basically, you wait for the dataset to be ready, then loop through all the items in your repeater using the forEachItem() callback, and reset the value of the text field based on the value in the boolean field.