DataBinding, formatting floats for forms and locales (i18n)

Hi There,

how would i implement a localized numberField in a form, that formats numbers with the proper amount of digits, the right decimalSeparator etc.?

right now I’m using

`{
				view: 'text',
				name: 'price',
				label: 'Preis',
				on: {
					onChange: formatNumber
				},
				validateEvent: 'key'
			}`

where formatNumber is defined:

`	function formatNumber (newV /*, oldV */) {
		if ($.isNumeric(newV)) {
			this.setValue(webix.i18n.numberFormat(newV));
		}
	}`

this is (the relevant part of) my locale:

`	webix.i18n.locales["de-DE"] = {
		groupDelimiter:".",
		groupSize:3,
		decimalDelimiter:",",
		decimalSize:2
	};`

annoying:
when i access the form values/data, i don’t get the actual numeric value, but the formatted string. Plus: even if the actual value hasn’t changed, it will get marked dirty by the form.

PS: where ain’t no function like

`webix.i18n.parseFloat`

, that makes use of my locale values (groupDelimiter,groupSize,decimalDelimiter,decimalSize).

Hi,

You can create the new control based on text and define own $setValue and $getValue methods. For example as in:

http://webix.com/snippet/a0eb8cb4

Hi, thanks! This looks good, I’ll give it a try! :slight_smile:

Works perfectly. Thank you!