mvvmcross - UITextField binding to a decimal. Can I automatically turn empty string to zero -
i have standard binding set in android on uitextview
local:mvxbind="text quantity"
where quantity int property.
if enter 123 say, gets assigned , setter called. delete text, 123 -> 12 -> 1 -> empty string, setter called each number not empty string infact following exception occurs:
mvxbind:error: 48.84 setvalue failed exception - formatexception: input string not in correct format
is there way of automatically converting empty string value 0 in binding? need value converter this? in fact bug?
thanks in advance.
this area has been discussed in https://github.com/slodge/mvvmcross/issues/350 nullable
additions in https://github.com/slodge/mvvmcross/issues/373 - people welcome contribute opinions (and/or code) there.
the current 'status quo' mvvmcross parse , represent valid decimal numbers. however, if number isn't valid - eg if it's string.empty or set of non-numeric characters - mvvmcross won't interpret these 0 (should "" zero? should "asdf" zero? should "123.456.7" zero? should "1234asd" zero? perhaps of these should nan
?).
if people need specific behaviour it's easy them implement behaviour - e.g. using custom control (subclassed uitextfield), using value converter, using custom binding (or overriding default binding), using string property on viewmodel, etc.
my personal opinion topic comes under validation
heading. in general, mvvmcross doesn't provide many hooks validation
@ present. it's been proposed long time - https://github.com/slodge/mvvmcross/issues/133 - no-one has shown interest. there simple validation samples in witherrors demo within https://github.com/slodge/mvvmcross-tutorials/tree/master/apiexamples. within apps i've written we've written , sub-classed ui controls reduce need validation - , in general we've tried avoid need text input can (users don't seem using keypads on phones)
Comments
Post a Comment