question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minimum character length before input

See original GitHub issue

Hi Ben!

I’m using a live search implementation on the site I’m building and I’d like to have a minumum character length before triggering the sprig request.

A google shows me this SO answer: https://stackoverflow.com/questions/66301453/minimum-number-of-characters-before-hx-get

which says I can use hx-trigger="keyup[target.value.length > 10]" but when I try and implement this via this code:

<input sprig s-trigger="keyup[target.value.length > 3] changed[target.value.length > 3] delay:200ms" s-replace="#search-results" class="site-header__search-input" type="search" name="keywords" aria-label="Search" placeholder="Search products" value="{{ keywordSearch }}">

I can’t get Sprig to fire at all. I’ve tried just using keyup with no changed or delay but no dice. Am I barking up the wrong tree here? Do you have any ideas on what might be going wrong?

Thanks!

Robin

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
bencrokercommented, Aug 10, 2022

This is a tricky one, since it throws the Sprig parser off, which takes the > to mean the end of the tag. I think I’m just going to recommend that you use a htmx attribute directly, which should work just fine.

<input sprig hx-trigger="keyup[target.value.length > 3] changed[target.value.length > 3] delay:200ms" s-replace="#search-results" class="site-header__search-input" type="search" name="keywords" aria-label="Search" placeholder="Search products" value="{{ keywordSearch }}">
0reactions
robzorcommented, Aug 22, 2022

Good idea, I’ll try there. Thanks again!

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML attribute: minlength - HTML: HyperText Markup Language
The minlength attribute defines the minimum number of characters (as UTF-16 code units) the user can enter into an <input> or <textarea> ....
Read more >
HTML input minlength Attribute - W3Schools
The minlength attribute specifies the minimum number of characters required in an input field. Note: The minlength attribute can be used with input...
Read more >
How to specify minimum & maximum number of characters ...
To set the minimum character limit in input field, we use <input> minlength attribute. This attribute is used to specify the minimum number ......
Read more >
Is there a minlength validation attribute in HTML5?
Use the minlength(/ maxlength) attribute. It specifies the minimum number of characters. For example, <input type="text" minlength ...
Read more >
How to set a mininum of characters a field can have
You could add the html minlength property to the input field. Alternatively you can add an onchange event to check the length of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found