Skip to content

Commit e517bf4

Browse files
committed
Fix widget id being unchangeable
While not recommended, the widget id should be able to be changed. And it definitely should not throw non-self-explanatory error messages. Change-Id: Ic2cdbde3d201e2af52616dea1be941d61452fd52
1 parent be680e0 commit e517bf4

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

doc/api/Widget.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
"properties": {
168168
"id": {
169169
"type": "string",
170-
"description": "A string to identify the widget by using selectors. IDs are optional. It is strongly recommended that they are unique within a page."
170+
"description": "A string to identify the widget by using selectors. IDs are optional. It is strongly recommended that they are unique within any component."
171171
},
172172
"class": {
173173
"type": "string",

src/tabris/Widget.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,10 @@ export default class Widget extends NativeObject {
227227
set id(value) {
228228
/** @type {string} */
229229
const id = types.string.convert(value);
230-
Object.defineProperty(this, '_id', {enumerable: false, writable: false, value: id});
230+
if (id === this._id) {
231+
return;
232+
}
233+
Object.defineProperty(this, '_id', {enumerable: false, writable: true, value: id});
231234
}
232235

233236
get id() {

test/tabris/widgets/Widget.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,11 @@ describe('Widget', function() {
239239
expect(widget.id).to.equal('foo');
240240
});
241241

242-
it('gets id property from widget.id', function() {
242+
it('can set id twice', function() {
243243
widget.id = 'foo';
244+
widget.id = 'bar';
244245

245-
expect(widget.id).to.equal('foo');
246+
expect(widget.id).to.equal('bar');
246247
});
247248

248249
it('stores class property in widget.classList', function() {

0 commit comments

Comments
 (0)