egroupware_official/api/js/etemplate/Et2Textbox/Et2NumberReadonly.ts
nathan f8a8cf69dc Et2Number format improvements
- If precision is set, always show that many digits after the decimal
- Better handling of formatting of initial value
2024-08-06 16:09:18 -06:00

46 lines
1.1 KiB
TypeScript

/**
* EGroupware eTemplate2 - Number widget (WebComponent)
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link https://www.egroupware.org
* @author Ralf Becker
*/
import {Et2TextboxReadonly} from "./Et2TextboxReadonly";
import {formatNumber} from "./Et2Number";
export class Et2NumberReadonly extends Et2TextboxReadonly
{
static get properties()
{
return {
...super.properties,
/**
* Precision of float number or 0 for integer
*/
precision: Number,
}
}
set_value(val)
{
if(val === null)
{
val = "";
}
else if("" + val !== "")
{
// use decimal separator from user prefs
const format = this.egw().preference('number_format') ?? ".";
val = formatNumber(parseFloat(val), format[0], format[1], this.precision);
}
// can not call super.set_value(), as it does not call the setter for value
super.value = val;
}
}
// @ts-ignore TypeScript is not recognizing that Et2Textbox is a LitElement
customElements.define("et2-number_ro", Et2NumberReadonly);