I cant get the getCustomText working on my website

Here is my current working code.

// Get the button and slider elements
let button72 = $w('#button72'); // Replace with the actual ID of button72
let slider1 = $w('#slider1');
let button71 = $w('#button71'); // Replace with the actual ID of button71
let button69 = $w('#button69'); // Replace with the actual ID of button69
let button74 = $w('#button74'); // Replace with the actual ID of button74

// Add an event handler to the slider to update buttons when it changes
slider1.onChange((event) => {
    // Get the numeric value from button72 (you may need to adjust this based on your button's structure)
    const buttonValue = parseFloat(button72.label.replace('$', ''));

    // Get the current value of the slider as a number
    const sliderValue = parseFloat(event.target.value);

    // Check if both values are valid numbers
    if (!isNaN(sliderValue) && !isNaN(buttonValue)) {
        // Calculate the result by multiplying the values
        const result = sliderValue * buttonValue;

        // Update button71 with the calculated result (including the dollar symbol)
        button71.label = `$${result.toFixed(2)}`; // Display the result as a dollar price

        // Extract the letter from button74's text
        const letter = button74.label.replace(/\d/g, ''); // Extracts non-digit characters (letters)

        // Update button69 to show the slider value with the extracted letter
        button69.label = `${sliderValue.toFixed(0)}${letter}`; // Display the slider value with the letter
    }
});

$w.onReady(function () {
    const slider = $w('#slider1');

    // Get the data for the current dynamic page from CMS
    const currentItem = $w('#dynamicDataset').getCurrentItem();

    if (currentItem) {
        // Get the minimum and maximum values from CMS using the field keys
        const minValue = parseFloat(currentItem.sliderMinValueInput); // Convert the text value to a number
        const maxValue = parseFloat(currentItem.stocknumber); // Convert the text value to a number
        const stepValue = parseFloat(currentItem.sliderMinValueInput); // Covert the text value to a number

        // Set the slider minimum and maximum values based on the CMS values
        slider.min = minValue;
        slider.max = maxValue;
        slider.step = stepValue;

        // Event handler for the minimum value input field (CMS value)
        slider.onChange(() => {
            const sliderValue = parseFloat(slider.value); // Get the current slider value
            // Your other code here for button interactions
        });
    }
});
import { cart } from 'wix-stores';

$w("#button76").onClick(() => {
  const productId = $w("#text92").text; // Retrieve the product ID
  const quantityString = $w("#button69").label; // Retrieve the quantity as a string

  // Remove non-numeric characters (letters) and convert to a number
  const quantity = Number(quantityString.replace(/[^0-9.]/g, ''));

  if (!productId || isNaN(quantity) || quantity <= 0) {
    console.error("Please enter a valid quantity.");
    return;
  }

  // Add the product to the cart with the cleaned quantity
  cart.addProducts([{
    productId,
    quantity,
  }])
  .then((updatedCart) => {
    // Product added to the cart
    const cartId = updatedCart._id;
    const cartLineItems = updatedCart.lineItems;
  })
  .catch((error) => {
    console.error(error);
  });
});

Now what i want to achieve in this code,
I want users to input the custom text like their username.
I used the code from Wix itself and adjusted it.

Wix code:
$w(‘#myProductPage’).getCustomText()
.then((customShirtText) => {
let FrontOfShirtText = customShirtText[0]; // ‘Hello’
let BackOfShirtText = customShirtText[1]; // ‘World’
})
.catch((error) => {
console.error(error);
});

My Code
$w(‘#getProduct’).getCustomText()
.then((customShirtText) => {
let FrontOfShirtText = CharacterID[0]; // ‘Hello’
})
.catch((error) => {
console.error(error);
});

Also the #getProduct is a textinput field but i keep getting error message
Property text does not exist on textinput

Can you reduce the amount of code above to solely what reproduces the error?

The text property doesn’t exist on TextInput elements. Perhaps the value property is what is wanted?

Can you link to where you got this code from?

1 Like