mirror of
https://github.com/discourse/discourse.git
synced 2025-01-31 02:49:29 +08:00
FIX: makes allowInitialValueMutation more restrictive
This commit is contained in:
parent
b3094e9954
commit
96cdc4e66e
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
},
|
},
|
||||||
|
|
|
@ -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");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user