Skip to content

Commit b254a07

Browse files
committed
fix(ApiFormItemElement): no selected value for enum
1 parent ab0c0eb commit b254a07

File tree

5 files changed

+134
-1
lines changed

5 files changed

+134
-1
lines changed

demo/W-11836777/W-11836777.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
openapi: 3.0.0
2+
info:
3+
title: eMPF API Specification - Contribution Module
4+
description: eMPF API Specification - Contribution Module
5+
version: 0.1.0
6+
paths:
7+
/cas/ad/contribution/external/v1/bill/list:
8+
get:
9+
tags:
10+
- ER-Portal-API
11+
summary: CON-PERIOD-BILLABLE CON - Retrieve period bill
12+
description: |
13+
**API ID:** CON-PERIOD-BILLABLE \
14+
**CM:** CM-Web-Employer-Contribution A1, A2, A3, A4, B1, B2, B3, B4 \
15+
**FS:** FS-UF-CON-REE-009,FS-UF-CON-CEE-001 \
16+
CON - Retrieve period bill
17+
parameters:
18+
- $ref: '#/components/parameters/pageSize'
19+
responses:
20+
'200':
21+
description: successfully
22+
content:
23+
application/json:
24+
schema:
25+
$ref: '#/components/schemas/periodBillableResponse'
26+
'400':
27+
$ref: '#/components/responses/400'
28+
security:
29+
- bearerAuth: []
30+
31+
components:
32+
parameters:
33+
pageSize:
34+
in: query
35+
required: true
36+
name: pageSize
37+
description: Page Size
38+
schema:
39+
enum:
40+
- 25
41+
- 50
42+
- 100
43+
example: 50
44+
type: integer
45+
schemas:
46+
GlobalSuccessResponse:
47+
type: object
48+
properties:
49+
success:
50+
type: boolean
51+
description: The flag indicates there is no bussiness error occurred in the request
52+
code:
53+
type: integer
54+
example: '200'
55+
periodBillableResponse:
56+
allOf:
57+
- $ref: '#/components/schemas/GlobalSuccessResponse'
58+
- properties:
59+
payload:
60+
$ref: '#/components/schemas/periodBillablesResDto'
61+
periodBillablesResDto:
62+
type: object
63+
properties:
64+
pageRecords:
65+
type: integer
66+
example: 50
67+
page:
68+
type: integer
69+
example: 0
70+
pageSize:
71+
type: integer
72+
example: 50
73+
totalPages:
74+
type: integer
75+
example: 3
76+
totalRecords:
77+
type: integer
78+
example: 139
79+
responses:
80+
'400':
81+
description: Business validation exception
82+
83+
securitySchemes:
84+
bearerAuth:
85+
type: http
86+
scheme: bearer
87+
bearerFormat: JWT

demo/api-form-item.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ class ComponentDemo extends DemoPage {
121121
enum: ['apple', 'banana', 'cherries', 'grapes', 'lemon', 'orange', 'pear', 'watermelon']
122122
}
123123
});
124+
125+
this.m12 = /** @type AmfFormItem */({
126+
name: '',
127+
value: 50,
128+
schema: {
129+
required: true,
130+
apiType: 'integer',
131+
inputLabel: 'Enum integer',
132+
inputType: 'text',
133+
enum: ['25', '50', '100']
134+
}
135+
});
124136
}
125137

126138
_readonlyHandler(e) {
@@ -306,6 +318,19 @@ class ComponentDemo extends DemoPage {
306318
@change="${this._valueHandler}"></api-form-item>
307319
<code>${this.v10}</code>
308320
</section>
321+
322+
<section class="card">
323+
<h3>Enum with integer options</h3>
324+
<api-form-item
325+
.readOnly="${readOnly}"
326+
.model="${this.m12}"
327+
?outlined="${outlined}"
328+
?compatibility="${compatibility}"
329+
name="enumIntModel"
330+
data-target="m12"
331+
@change="${this._valueHandler}"
332+
value="${50}"></api-form-item>
333+
</section>
309334
`;
310335
}
311336
}

demo/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"annotated-oauth2/annotated-oauth2.raml": "RAML 1.0",
77
"APIC-298/APIC-298.json": ["OAS 2.0", "application/json"],
88
"APIC-289/APIC-289.yaml": ["OAS 2.0", "application/yaml"],
9+
"W-11836777/W-11836777.yaml": ["OAS 3.0", "application/yaml"],
910
"no-auto-encoding/no-auto-encoding.raml": "RAML 1.0"
1011
}

src/ApiFormItemElement.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ export class ApiFormItemElement extends ValidatableMixin(LitElement) {
502502
// non required items should have an option to set a null value.
503503
values.unshift('');
504504
}
505+
const selectedValue = schema.apiType === 'integer' ? value.toString() : value;
505506
return html`
506507
<anypoint-dropdown-menu
507508
name="${name}"
@@ -517,7 +518,7 @@ export class ApiFormItemElement extends ValidatableMixin(LitElement) {
517518
<anypoint-listbox
518519
slot="dropdown-content"
519520
attrforselected="data-value"
520-
.selected="${value}"
521+
.selected="${selectedValue}"
521522
?compatibility="${compatibility}"
522523
@selected-changed="${this._listSelectionHandler}"
523524
>

test/ApiFormItemElement.enum.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ describe('ApiFormItemElement', () => {
111111
const item = items[0];
112112
assert.equal(item.getAttribute('data-value'), '', 'has no value');
113113
});
114+
115+
it('renders template when no enum values', async () => {
116+
element.model = {
117+
name: '',
118+
value: 50,
119+
schema: {
120+
required: true,
121+
apiType: 'integer',
122+
inputLabel: 'Enum integer',
123+
inputType: 'text',
124+
enum: ['25', '50', '100']
125+
}
126+
};
127+
await nextFrame();
128+
await nextFrame();
129+
130+
const listBox = element.shadowRoot.querySelector('anypoint-listbox');
131+
assert.isDefined(listBox.selected, 'listbox has the property');
132+
});
114133
});
115134

116135
describe('Enum values: a11y', () => {

0 commit comments

Comments
 (0)