swiftui: Value is not updated on numberformatted Textfield like currency

I'd just like to know whether there's a bug in macOS or if I have to make changes in code with currency formatted TextFields.

My problem: just a simple TextField in SwiftUI like

TextField("amountOnDeadline",value: $startValue, formatter: Formatters.currencyFormatter)

The formatter ist pretty simple:

	static let currencyFormatter: NumberFormatter = {
		let formatter = NumberFormatter()
		formatter.numberStyle = .currency
		formatter.maximumFractionDigits = 2
		return formatter
	}()

Build and run! The offered field is displayed as currency field. Great! But when I enter a number like 123, the field is reset to 0.00 € (or the value displayed on start). Only when I exactly mark the 0.00 without the currency symbol and enter a value, the new value is taken.

This is not very user friendly. Is it something I have to live with or is there a solution for this problem? e.g. a special config in NumberFormatter.

Answered by mihema in 731736022

From a friend on stackoverflow you have to use this way of formatting:

TextField("amountOnDeadline",value: $startValue, format: .currency(code: Locale.current.currencyCode ?? "EUR"))
Accepted Answer

From a friend on stackoverflow you have to use this way of formatting:

TextField("amountOnDeadline",value: $startValue, format: .currency(code: Locale.current.currencyCode ?? "EUR"))
swiftui: Value is not updated on numberformatted Textfield like currency
 
 
Q