mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 16:24:17 +08:00
a0283305ca
Followup db993cf8fd
Since in the above commit we converted integer site settings
to actual integers then set that as the new `buffered.value`,
the overridden indicator technically thinks the value has changed,
even if the user sets it back to the default:
```
overridden: propertyNotEqual("setting.default", "buffered.value"),
```
We can fix this by converting the parsed integer back to a string
before setting the buffered setting value.
45 lines
1.3 KiB
Plaintext
45 lines
1.3 KiB
Plaintext
import Component from "@glimmer/component";
|
|
import { on } from "@ember/modifier";
|
|
import { action } from "@ember/object";
|
|
import SettingValidationMessage from "admin/components/setting-validation-message";
|
|
import SiteSettingDescription from "admin/components/site-settings/description";
|
|
|
|
export default class SiteSettingsInteger extends Component {
|
|
@action
|
|
updateValue(event) {
|
|
const num = parseInt(event.target.value, 10);
|
|
|
|
if (isNaN(num)) {
|
|
return;
|
|
}
|
|
|
|
// Settings are stored as strings, this way the main site setting component
|
|
// doesn't get confused and think the value has changed from default if the
|
|
// admin sets it to the same number as the default.
|
|
this.args.changeValueCallback(num.toString());
|
|
}
|
|
|
|
@action
|
|
preventDecimal(event) {
|
|
if (event.key === "." || event.key === ",") {
|
|
event.preventDefault();
|
|
}
|
|
}
|
|
|
|
<template>
|
|
<input
|
|
{{on "keydown" this.preventDecimal}}
|
|
{{on "input" this.updateValue}}
|
|
type="number"
|
|
value={{@value}}
|
|
min={{if @setting.min @setting.min null}}
|
|
max={{if @setting.max @setting.max null}}
|
|
class="input-setting-integer"
|
|
step="1"
|
|
/>
|
|
|
|
<SettingValidationMessage @message={{@validationMessage}} />
|
|
<SiteSettingDescription @description={{@setting.description}} />
|
|
</template>
|
|
}
|