inertia-bootstrap-forms 2.1.3 → 2.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -209,6 +209,10 @@ export const FormContainer: DefineComponent<{
209
209
  method: {
210
210
  default: 'post'
211
211
  },
212
+ autoTab: {
213
+ type: Boolean,
214
+ default: true,
215
+ },
212
216
  only: {
213
217
  type: Array,
214
218
  default: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Create bootstrap forms with inertia and twitter bootstrap",
5
5
  "main": "dist/inertia-bootstrap-forms.cjs.js",
6
6
  "module": "dist/inertia-bootstrap-forms.es.js",
@@ -15,6 +15,10 @@ export default defineComponent({
15
15
  method: {
16
16
  default: 'post'
17
17
  },
18
+ autoTab: {
19
+ type: Boolean,
20
+ default: true,
21
+ },
18
22
  only: {
19
23
  type: Array,
20
24
  default: [],
@@ -90,6 +94,37 @@ export default defineComponent({
90
94
  }
91
95
  },
92
96
  methods: {
97
+ handleAutoTab(event) {
98
+ if (this.formEl?.dataset.autotab !== 'true') return;
99
+
100
+ const el = event.target;
101
+ if (!['INPUT', 'TEXTAREA'].includes(el.tagName)) return;
102
+
103
+ const maxLength = el.maxLength;
104
+ if (maxLength > 0 && el.value.length >= maxLength) {
105
+ this.focusNextField(el);
106
+ }
107
+ },
108
+ focusNextField(current) {
109
+ const focusable = Array.from(
110
+ this.formEl.querySelectorAll('input, select, textarea')
111
+ ).filter(el =>
112
+ !el.disabled &&
113
+ el.tabIndex !== -1 &&
114
+ el.type !== 'hidden' &&
115
+ el.offsetParent !== null
116
+ );
117
+
118
+ const index = focusable.indexOf(current);
119
+ const next = focusable[index + 1];
120
+
121
+ if (next) {
122
+ next.focus();
123
+ if (next.tagName !== 'SELECT' && typeof next.select === 'function') {
124
+ next.select();
125
+ }
126
+ }
127
+ },
93
128
  reset() {
94
129
  this.form.reset();
95
130
  },
@@ -161,6 +196,8 @@ export default defineComponent({
161
196
  <form ref="formEl"
162
197
  :action="url"
163
198
  :method="method"
199
+ :data-autotab="autoTab ? 'true' : ''"
200
+ @input="handleAutoTab"
164
201
  @submit.prevent="submit"
165
202
  @reset="$emit('reset')"
166
203
  :class="{'form-processing': form.processing}"