Skip to content

Commit 6009d72

Browse files
authored
feat(forms): add form prop to all inputs. fixes bootstrap-vue#2154 (bootstrap-vue#2172)
* feat(forms): add form prop to all inputs. fixes bootstrap-vue#2154 form controls that are wrapped in other elements internally were not transferring the form attribute to the input. fixes bootstrap-vue#2154 * Update form-file.js add form attribute * Update form-input.js add form attribute * Update form-select.js add form attribute * Update form-select.js * Update form-textarea.js add form attribute * Update form-radio-check.js * Update form-checkbox.js add form attribute * Update form-checkbox-group.js add form attribute * Update form-radio.js add form attribute * Update form-radio-group.js add form attribute * Update form-input.spec.js add some basic tests * Update form-input.spec.js
1 parent ab44375 commit 6009d72

File tree

11 files changed

+44
-0
lines changed

11 files changed

+44
-0
lines changed

src/components/form-checkbox/form-checkbox-group.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default {
3131
props: {
3232
id: this.safeId(`_BV_check_${idx}_opt_`),
3333
name: this.name,
34+
form: this.form || null,
3435
value: option.value,
3536
required: this.name && this.required,
3637
disabled: option.disabled
@@ -70,6 +71,10 @@ export default {
7071
type: [String, Number, Object, Array, Boolean],
7172
default: null
7273
},
74+
form: {
75+
type: String,
76+
default: null
77+
},
7378
validated: {
7479
type: Boolean,
7580
default: false

src/components/form-checkbox/form-checkbox.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default {
3737
id: this.safeId(),
3838
type: 'checkbox',
3939
name: this.get_Name,
40+
form: this.get_Form || null,
4041
disabled: this.is_Disabled,
4142
required: this.is_Required,
4243
autocomplete: 'off',

src/components/form-file/form-file.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default {
2727
name: this.name,
2828
disabled: this.disabled,
2929
required: this.required,
30+
form: this.form || null,
3031
capture: this.capture || null,
3132
accept: this.accept || null,
3233
multiple: this.multiple,

src/components/form-input/form-input.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export default {
4444
attrs: {
4545
id: self.safeId(),
4646
name: self.name,
47+
form: this.form || null,
4748
type: self.localType,
4849
disabled: self.disabled,
4950
required: self.required,

src/components/form-input/form-input.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ describe('form-input', async () => {
9191
expect(input.attributes('id')).toBe('foobar')
9292
})
9393

94+
it('has safeId after mount when no id provided', async () => {
95+
const wrapper = mount(Input, {
96+
attachToDocument: true
97+
})
98+
const input = wrapper.find('input')
99+
return wrapper.vm.$nextTick()
100+
.then(function () {
101+
expect(input.attributes('id')).toBeDefined()
102+
})
103+
})
104+
105+
it('has form attribute when form prop set', async () => {
106+
const wrapper = mount(Input, {
107+
propsData: {
108+
form: 'foobar'
109+
}
110+
})
111+
const input = wrapper.find('input')
112+
expect(input.attributes('form')).toBe('foobar')
113+
})
114+
94115
it('renders text input by default', async () => {
95116
const wrapper = mount(Input)
96117
const input = wrapper.find('input')

src/components/form-radio/form-radio-group.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default {
3030
props: {
3131
id: this.safeId(`_BV_radio_${idx}_opt_`),
3232
name: this.name,
33+
form: this.form || null,
3334
value: option.value,
3435
required: Boolean(this.name && this.required),
3536
disabled: option.disabled
@@ -69,6 +70,10 @@ export default {
6970
type: [String, Object, Number, Boolean],
7071
default: null
7172
},
73+
form: {
74+
type: String,
75+
default: null
76+
},
7277
validated: {
7378
// Used for applying hte `was-validated` class to the group
7479
type: Boolean,

src/components/form-radio/form-radio.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default {
2727
id: this.safeId(),
2828
type: 'radio',
2929
name: this.get_Name,
30+
form: this.get_Form || null,
3031
required: this.get_Name && this.is_Required,
3132
disabled: this.is_Disabled,
3233
autocomplete: 'off'

src/components/form-select/form-select.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default {
4040
attrs: {
4141
id: this.safeId(),
4242
name: this.name,
43+
form: this.form || null,
4344
multiple: this.multiple || null,
4445
size: this.computedSelectSize,
4546
disabled: this.disabled,

src/components/form-textarea/form-textarea.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export default {
2222
attrs: {
2323
id: this.safeId(),
2424
name: this.name,
25+
form: this.form || null,
2526
disabled: this.disabled,
2627
placeholder: this.placeholder,
2728
required: this.required,

src/mixins/form-radio-check.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export default {
8989
get_Name () {
9090
return (this.is_Child ? (this.$parent.name || this.$parent.safeId()) : this.name) || null
9191
},
92+
get_Form () {
93+
return this.is_Child ? (this.$parent.form || this.form) : this.form
94+
},
9295
buttonClasses () {
9396
// Same for radio & check
9497
return [

src/mixins/form.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default {
1212
required: {
1313
type: Boolean,
1414
default: false
15+
},
16+
form: {
17+
type: String,
18+
default: null
1519
}
1620
}
1721
}

0 commit comments

Comments
 (0)