GetCurrentItem

pls, what is wrong on this code? I want, when value in fieldname “termin” is empty then “Text42” show … else when there is something value in “termin”, it remains hidden

$w.onReady( function () {

$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
let items = $w(“#dataset1”).getCurrentItem().termin;
if (items === “”) {
$w(“#text42”).show();
} else {
$w(“#text42”).hide();
}
});

1 Like

something this, but still doesnt work…

$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
let items = $w(“#dataset1”).getCurrentItem().termin;
if (items === valueOf( null )) {
$w(“#line2”).hide();
} else {
$w(“#line2”).show();
}
});

also does not work … I do not know where I’m making a mistake …

$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
$w(“#dataset1”).onReady( () => {
let item = $w(“#dataset1”).getCurrentItem();
if (item.termin) {
$w(“#line2”).hide();
} else {
$w(“#line2”).show();
}
} );
} );

The code it self looks OK, you can check:

  1. Your code panel error for other type of errors around (Extra char and stuff that you didn’t plan to have there)
  2. names of the UI components
  3. name of the field in the collection (in the screen showed below)

Thanky you , but unfortunately it is not …

share your site I can give it additional look…

https://www.cestaspolu.cz/planovane-cesty

Hi Man, (I think that I found what you try to do :slight_smile:
Explanation: Dataset is the collection data. The current item not change on each container in the repeater. So in your case in onItemReady you can use the itemData in order to get your current container entity.
So change your code to the following and its should work:

$w(“#repeater1”).onItemReady( ($w, itemData, index) => {
if (itemData.termin === “”) {
$w(“#text46”).show();
} else {
$w(“#text46”).hide();
}
});

GL, Erez

1 Like

hi, its work !!! Thanks a lot man !!! :slight_smile:

hi sorry, i think i got the same problem? what should i tweak?

let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
$w(" #dataset1 ").onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 500;
// set the fullText variable to be the text from the collection
fullText = $w(’ #dataset1 ‘).getCurrentItem().description;
// if no text to display, collapse the text element and the button
if (!fullText) {
$w(’ #gamedescription ‘).collapse();
} else {
// if the text has fewer or the same number of characters as shortTextLength characters, display it as is and collapse the “Show More” button
if (fullText.length <= shortTextLength) {
$w(’ #gamedescription ‘).text = fullText;
} else {
// create the shortened version of the text and display it in the text element
shortText = fullText.substr(0, shortTextLength) + “…”;
$w(’ #gamedescription ').text = shortText;
}
}
});

Yours isn’t the same problem as the original forum post, they were using repeaters, whereas it seems you are just using the code for the show more button and working with Dynamic Text.

Have you read this tutorial about it here , as you seem to be missing everything for the button itself.

getting crazy what I do have wrong in this full code, I am trying to apply to my dynamic page

//-------------Imports-------------//

import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;

//-------------Global Variables-------------//

// Current product.
let currentItem;

//-------------Page Setup-------------//

$w.onReady( async function () {
// Set the global product variable to the currently displayed product.
currentItem = await $w(‘#dynamicDataset’).getCurrentItem();
// Load the current product’s reviews using the initReviews() function.
initReviews();
});

// Loads the current product’s reviews.
async function initReviews() {
// Filter the “Reviews” dataset to contain only the reviews on the currently displayed product.
await $w(‘#dynamicDataset’).setFilter(wixData.filter().eq(‘itemId’, item._id));
// Show the reviews after the filter was set and applied on the dataset
showReviews();
// Load the current product’s statistics using the loadStatistics() function.
loadStatistics();
}

// Load the current product’s statistics.
async function loadStatistics() {
// Get the statistics data based on the current product’s ID.
const stats = await wixData.get(‘CommentStats’, item._id);
// If statistics data for the product was found:
if (stats) {
// Compute the product’s average rating by dividing the total points by the number of ratings.
let avgRating = (Math.round(stats.rating * 10 / stats.count) / 10);
// Compute the percentage of reviewers that recommend the product.
let percentRecommended = Math.round(stats.recommended / stats.count * 100);
// Get the ratings element.
let ratings = $w(‘#generalRatings’);
// Set the ratings element’s average rating to the value calculated above.
ratings.rating = avgRating;
// Set the ratings element’s number of ratings to the count value from the statistics data.
ratings.numRatings = stats.count;
// Set the text for the recommended percentage element.
$w(‘#recoPercent’).text = ${percentRecommended} % would recommend;
// Show the ratings element.
$w(‘#generalRatings’).show();
// If there is no statistics data for the product:
} else {
// Set the text for the recommended percentage element to reflect the fact that there are no reviews.
$w(‘#recoPercent’).text = ‘There are no reviews yet’;
}
// Show the recommended percentage element only after it is populated to avoid flickering.
$w(‘#recoPercent’).show();
}

//-------------Repeater Setup -------------//

// Set up each item in the reivews repeater as it is loaded.
export function reviewsRepeater_itemReady_1($w, itemData, index) {
// If the reviewer recommends the item:
if (itemData.recommends) {
// Set the "recommend text.
$w(‘#recommendation’).text = ‘I recommend this product.’;
// If the reviewer does not recommend the item:
} else {
// Set the “don’t recomend” text.
$w(‘#recommendation’).text = “I don’t recommend this product.”;
}

// If a photo was uploaded for the review:
if (itemData.photo) {
// Set the image URL from the item data.
$w(‘#reviewImage’).src = itemData.photo;
// Expand the image.
$w(‘#reviewImage’).expand();
}

// Set the ratings element’s rating value.
$w(‘#oneRating’).rating = itemData.rating;

// Get the date that the review was entered.
let date = itemData._createdDate;
// Format the date according to the date format settings on the user’s computer.
$w(‘#submissionTime’).text = date.toLocaleString();
}

//-------------Data Setup -------------//

// Perform some setup when the dataset filter was completed.
export function showReviews() {
// If at least one review has been submitted:
if ($w(‘#dataset1’).getTotalCount() > 0) {
// Expand the strip that displays the reviews.
$w(‘#reviewsStrip’).expand();
// If there are no reviews:
} else {
// Collapse the strip that displays the reviews.
$w(‘#reviewsStrip’).collapse(); //otherwise, hide it
}
}

//-------------Event Handlers -------------//

// Set the action that occurs when a user clicks the “Write a Review” button.
export async function addReview_click(event, $w) {
// Create an object containing the current product’s ID to be sent to the review writing lightbox.
const dataForLightbox = {
itemId: item._id
};
// Open the “Review Box” lightbox, send it the object created above, and wait for it to close.
let result = await wixWindow.openLightbox(‘Comments Stockout’, dataForLightbox);
// After the review lightbox is closed, refresh the reviews dataset so the new review appears on the page.
$w(‘#dataset1’).refresh();
// Reload the current products statistics to reflect the new rating.
loadStatistics();
// Show a thank you message.
$w(‘#thankYouMessage’).show();
}

// Set the action that occurs when a user clicks the “Load More” text.
export function resultsPages_click_1(event, $w) {
// Load additional reviews into the reviews repeater.
$w(‘#dataset1’).loadMore();
}