Skip to content

Commit a6ea836

Browse files
committed
Make autosubmit min length configurable with stimulus value
1 parent c346fbf commit a6ea836

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

app/javascript/controllers/forms/autosubmit.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export default class extends Controller {
1010
type: Number,
1111
default: 0,
1212
},
13+
mininumLength: {
14+
type: Number,
15+
default: 0,
16+
},
1317
};
1418

1519
connect() {
@@ -28,10 +32,14 @@ export default class extends Controller {
2832
return;
2933
}
3034

31-
if (event.target.value.length >= 3) {
35+
if (event.target.value.length >= this.mininumLengthValue) {
3236
this.element.requestSubmit();
3337
} else {
34-
console.log('Not submitting until 3 or more characters');
38+
console.log(
39+
'Not submitting until',
40+
this.mininumLengthValue,
41+
'characters',
42+
);
3543
}
3644
}
3745
}

app/views/searches/combobox.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def view_template
2727
data: {
2828
controller: "autosubmit-form",
2929
autosubmit_delay_value: 300,
30+
autosubmit_minimum_length_value: 3,
3031
turbo_frame: :search
3132
} do |f|
3233
div(class: "flex items-center flex-row pl-2 col-gap-xs") do

0 commit comments

Comments
 (0)