Minimum number of characters before hx-get? - htmx

I'm wondering if it's possible to set a minimum number of characters before the request is dispatched in an input?

You can filter events in html using a filter expression, and use that to examine the number of characters in the input:
<input ... hx-trigger="keyup[target.value.length > 10]" ...>

Related

add element or symbol to a :value

I have two input text which, its :value is a value that is in a state in a store, I have two inputs, and in the store an array with two elements, where it assigns one to each input and shows it to me, but I want add a symbol either % or some text at the end of the input, how can I do it, can this be added in the :value?
<input
type="text"
class="text-center"
:value="filtersStore.absorptionValue[0]"
#input="event => filtersStore.handleAbsortionValue(event.target.value)"
>
in the input value I want to add the text or the symbol
You can use template literals with Vue's data bindings, e.g. to append a percent sign:
:value="`${filtersStore.absorptionValue[0]}%`"

Vue 3: Conditional v-if on hmtl attributes

I'm trying to conditional rendering an HTML Elements attribute:
EG:
<InputNumber v-model:value="example[index].number"
:min="collector.attr[0] ? collector.attr[0] : 0"
:max="collector.attr[1] ? collector.attr[1] : 0"
:step="0.01"
style="min-width: 120px;"/>
The Problem: the minimum Value of 0 is set (collector.attr[0] = null), but I want eg. that user is able to enter '-100'
The Goal: if the collector.attr[1] is "null" i want to remove the ":min" attribute - resp. only allow this attribute, if there is a minimum value set.
Like so:
<InputNumber
v-if="collector.attr[0]" => then :min="collector.attr[0]"
/>
Thank you very much for your help :)
Probably you can set a minimum value beyond which a user is not expected to input anything. Something like this
<InputNumber :min="collector.attr[0] ? collector.attr[0] : -Number.MAX_VALUE" />
Where Number.MAX_VALUE is maximum allowed float value in java script, so adding - in it makes it negative.

How to validate input text length in material input?

I am developing an application using angular dart. I am using angular dart material input for getting input from user.
I have a multiline text input for which I use material input and type="text".
I have made this field "required" but the problem is when the user enters white space or enter, the "required" is gone. I need a attribute where i can specify a constraint that at least one non-white space character must be entered.
How to achieve this?
Here is my code where I have used material input:
<material-input
ngControl="textAnswer" [(ngModel)]="answer" multiline
type="text" label="Your answer" required>
</material-input>
As per documentation you can use all input elements attribute with it.
All of the attributes that can be used with normal <input> and <textarea> elements can be used on elements inside <mat-form-field> as well
So use HTML5 pattern attribute to match the custom pattern(regular expression).
<material-input
ngControl="textAnswer" [(ngModel)]="answer" multiline
pattern="[\s\S]*\S[\s\S]*"
type="text" label="Your answer" required>
</material-input>
[\s\S]*\S[\s\S]* will help to match a string with at least one non-space character.
NOTE : To include all other character use [\S\s] since . doesn't include a newline character.

How to split a string in angular 2

I have an email sending scenario in which there is an input box of 'To'(whom you want to send a message).
app.html
<input type="text" class="form-control" [(ngModel)]="email.Tos">
Now I want that when a user input the multiple emailId in input box by comma separated, then in my model, 'Tos' value should bind in an Array of string.
Like : ["abc#gmail,com" , "xyz#gmail.com"].
Now, please tell me how to split the input box value as per my requirement.
You need to use split() function.
Component
let toArray = this.email.Tos.split(",");
variable toArray will contain an array of emails.
Please check split

Using repeat.for with bound number

Consider sample below:
//edit.html
<input type="number" step="1" value.bind="number" />
<div repeat.for="num of number">${num}</div>
//edit.ts
export class Edit {
number: number = 2;
}
I expect to see 2 divs on first page load and number of divs should change when I change number in input. Instead I get error
Value for 'number' is non-repeatable
I figured it out. If you bind input field to variable, even when variable is number, it will be changed to string when changed by user. In my case, number became string once changed in input field. I used this gist to help me solve this problem:
https://gist.github.com/jdanyow/d9d8dd9df7be2dd2f59077bad3bfb399
It offers custom element and attribute for binding numbers to input fields.