This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/number-field.js.es6
Jarek Radosz 5d4b240453
DEV: Provide radix argument to parseInt (#8281)
* DEV: Provide radix 10 argument to parseInt

* DEV: Provide radix 16 argument to parseInt

* DEV: Remove unnecessary parseInt calls

* Fix year formatting

parseInt was used here to convert decimals to ints
2019-11-12 10:47:42 +01:00

29 lines
620 B
JavaScript

import discourseComputed from "discourse-common/utils/decorators";
export default Ember.TextField.extend({
classNameBindings: ["invalid"],
@discourseComputed("number")
value: {
get(number) {
return parseInt(number, 10);
},
set(value) {
const num = parseInt(value, 10);
if (isNaN(num)) {
this.set("invalid", true);
return value;
} else {
this.set("invalid", false);
this.set("number", num);
return num.toString();
}
}
},
@discourseComputed("placeholderKey")
placeholder(key) {
return key ? I18n.t(key) : "";
}
});