Skip to content

Commit bd62bcc

Browse files
authored
Merge pull request #1 from cravindra/scoped-radio-groups
Scoped radio groups
2 parents 721a4ee + 51147fa commit bd62bcc

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ test/e2e/reports
88
stats.json
99
typings/
1010
typings.json
11+
.idea/

src/fields/core/fieldRadios.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default {
2323
}
2424
},
2525
id() {
26-
return this.schema.model;
26+
return this.getFieldID(this.schema, true);
2727
}
2828
},
2929

test/unit/specs/fields/fieldRadios.spec.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,24 @@ describe("FieldRadios.vue", () => {
123123
expect(labelList.at(6).classes()).to.not.include("is-checked");
124124
});
125125
});
126+
127+
describe("test 'name' attribute for the radio group", () => {
128+
it("should render the same 'name' attribute for all input[type=radio] within an instance", () => {
129+
const nameAttribute = radios.at(0).attributes().name;
130+
expect(radios.is(`input[name="${nameAttribute}"]`));
131+
});
132+
it("should render different 'name' attribute for all input[type=radio] across different instances", () => {
133+
const nameAttribute = radios.at(0).attributes().name;
134+
expect(radios.is(`input[name="${nameAttribute}"]`));
135+
136+
createField2({ schema, model, disabled: false });
137+
138+
const nameAttribute2 = radios.at(0).attributes().name;
139+
expect(radios.is(`input[name="${nameAttribute2}"]`));
140+
141+
expect(nameAttribute).not.to.equal(nameAttribute2);
142+
});
143+
});
126144
});
127145

128146
describe("check static values with { value, name } objects (default key name)", () => {
@@ -221,6 +239,24 @@ describe("FieldRadios.vue", () => {
221239
expect(labelList.at(6).classes()).to.not.include("is-checked");
222240
});
223241
});
242+
243+
describe("test 'name' attribute for the radio group", () => {
244+
it("should render the same 'name' attribute for all input[type=radio] within an instance", () => {
245+
const nameAttribute = radios.at(0).attributes().name;
246+
expect(radios.is(`input[name="${nameAttribute}"]`));
247+
});
248+
it("should render different 'name' attribute for all input[type=radio] across different instances", () => {
249+
const nameAttribute = radios.at(0).attributes().name;
250+
expect(radios.is(`input[name="${nameAttribute}"]`));
251+
252+
createField2({ schema, model, disabled: false });
253+
254+
const nameAttribute2 = radios.at(0).attributes().name;
255+
expect(radios.is(`input[name="${nameAttribute2}"]`));
256+
257+
expect(nameAttribute).not.to.equal(nameAttribute2);
258+
});
259+
});
224260
});
225261

226262
describe("check static values with { id, label } objects (custom key name with `radiosOptions`)", () => {
@@ -323,5 +359,23 @@ describe("FieldRadios.vue", () => {
323359
expect(labelList.at(6).classes()).to.not.include("is-checked");
324360
});
325361
});
362+
363+
describe("test 'name' attribute for the radio group", () => {
364+
it("should render the same 'name' attribute for all input[type=radio] within an instance", () => {
365+
const nameAttribute = radios.at(0).attributes().name;
366+
expect(radios.is(`input[name="${nameAttribute}"]`));
367+
});
368+
it("should render different 'name' attribute for all input[type=radio] across different instances", () => {
369+
const nameAttribute = radios.at(0).attributes().name;
370+
expect(radios.is(`input[name="${nameAttribute}"]`));
371+
372+
createField2({ schema, model, disabled: false });
373+
374+
const nameAttribute2 = radios.at(0).attributes().name;
375+
expect(radios.is(`input[name="${nameAttribute2}"]`));
376+
377+
expect(nameAttribute).not.to.equal(nameAttribute2);
378+
});
379+
});
326380
});
327381
});

0 commit comments

Comments
 (0)