FIX: makes allowInitialValueMutation more restrictive

This commit is contained in:
Joffrey JAFFEUX 2017-11-24 13:15:02 +01:00 committed by GitHub
parent b3094e9954
commit 96cdc4e66e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -15,7 +15,7 @@
{{/each}} {{/each}}
</ul> </ul>
{{#if editingPermissions}} {{#if editingPermissions}}
{{combo-box content=category.availableGroups value=selectedGroup}} {{combo-box allowInitialValueMutation=true content=category.availableGroups value=selectedGroup}}
{{combo-box class="permission-selector" {{combo-box class="permission-selector"
nameProperty="description" nameProperty="description"
content=category.availablePermissions content=category.availablePermissions

View File

@ -11,7 +11,7 @@ export default SelectKitComponent.extend({
classNames: "single-select", classNames: "single-select",
computedValue: null, computedValue: null,
value: null, value: null,
allowInitialValueMutation: true, allowInitialValueMutation: false,
@on("didReceiveAttrs") @on("didReceiveAttrs")
_compute() { _compute() {
@ -47,6 +47,10 @@ export default SelectKitComponent.extend({
}, },
_beforeWillComputeValue(value) { _beforeWillComputeValue(value) {
if (!isEmpty(this.get("content")) && isEmpty(value) && isNone(this.get("none"))) {
value = this.valueForContentItem(get(this.get("content"), "firstObject"));
}
switch (typeof value) { switch (typeof value) {
case "string": case "string":
case "number": case "number":
@ -58,10 +62,6 @@ export default SelectKitComponent.extend({
willComputeValue(value) { return value; }, willComputeValue(value) { return value; },
computeValue(value) { return value; }, computeValue(value) { return value; },
_beforeDidComputeValue(value) { _beforeDidComputeValue(value) {
if (!isEmpty(this.get("content")) && isEmpty(value) && isNone(this.get("none"))) {
value = this.valueForContentItem(get(this.get("content"), "firstObject"));
}
this.setProperties({ computedValue: value }); this.setProperties({ computedValue: value });
return value; return value;
}, },

View File

@ -282,8 +282,8 @@ componentTest('supports keyboard events', {
}); });
componentTest('supports mutating value when no value given', { componentTest('with allowInitialValueMutation', {
template: '{{single-select value=value content=content}}', template: '{{single-select value=value content=content allowInitialValueMutation=true}}',
beforeEach() { beforeEach() {
this.set("value", ""); this.set("value", "");
@ -292,7 +292,7 @@ componentTest('supports mutating value when no value given', {
test(assert) { test(assert) {
andThen(() => { andThen(() => {
assert.equal(this.get("value"), "1"); assert.equal(this.get("value"), "1", "it mutates the value on initial rendering");
}); });
} }
}); });