Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
 
Answered
Minimum length for q2-input

Is there a way to have a minimum length for q2-input fields? e.g. to ensure that a phone number is 10 digits, etc

Posted 4 years ago
Votes Newest

Answers


Hi Tanner,

The tecton input doesn't come with any builtin validation (see the docs for more info).

However, this allows the devs to validate it to match our use case using JS. You can use the format modifier to help the user identify the expectation as well. See format docs for more info on phone modifer. The modifier will handle the input limitations for you.

Here is an example of a validation function that you could write, if you are concerned the format modifier is not enough client side validation:


function verifyPhoneNumber(field) {
    const lengthValid = field.value.replace("/D/g", "").length >= 10 || field.value.length == 0;
    const errorMsg = "Phone number can't be more than 10 digits.";
    const errorSet = field.errors.includes(errorMsg);
    const invalidPhoneField = !lengthValid;

    if (invalidPhoneField && !errorSet) {
        field.errors.push(errorMsg);
    } else if (!invalidPhoneField && errorSet) {
        const elementToRemove = field.errors.indexOf(errorMsg);
        field.errors.splice(elementToRemove, 1);
    }
}
field = document.getElementById("phone");
field.addEventListener("input", function(event) {
		event.stopPropagation();
		this.value = event.detail.value;
		verifyPhoneNumber(this);
});

I hope that helps!

96 Views
1 Answer
4 years ago
4 years ago
Tags