If there’s a space character in search ignore it

  1. Hi All,

  2. So I have a search box and a go button on my wix page (all linked to a repeater).

  3. I noticed that iPads and iPhones put up suggestive text that includes a space at the end of a word. Ie you start typing ’Champa’ and the suggestive text offers ”Champagne ” (with a space at the end). You select it and it goes into your search box.

  4. I would like my search to Ignore the last space then run the normal search code.

Is the a line of code I could use to ignore the last space and then trigger the search?

Thank you in advance

John

my Current code is

import wixData from ‘wix-data’;

$w.onReady(function () {
//TODO: write your page related code here…

$w(“#dataset1”).setSort( wixData.sort()
.ascending(“productName”)
);
});

export function button1_click(event) {
//Add your code for this event here:
let SearchValue = $w(“#input1”).value;
$w(“#dataset1”).setFilter(wixData.filter().contains(‘productName’, SearchValue)
.or(wixData.filter().contains(‘category’, SearchValue))
.or(wixData.filter().contains(‘country’, SearchValue))
.or(wixData.filter().contains(‘grapeVariety’, SearchValue))
)

console.log(SearchValue);

}

John,

The trim() function removes spaces from both sides of a string.

let SearchValue = $w("#input1").value.trim();