BorisMoore / jsviews

Interactive data-driven views, MVVM and MVP, built on top of JsRender templates
http://www.jsviews.com/#jsviews
MIT License
856 stars 130 forks source link

Value does not link to radio buttons if it's integer #377

Closed alexx-grand closed 7 years ago

alexx-grand commented 7 years ago

Hi! Is it expected behavior? Here is a code snippet https://jsfiddle.net/23sp0wnj/

alexx-grand commented 7 years ago

https://jsfiddle.net/j317d0az/

I found a solution but it is not look good as for me

BorisMoore commented 7 years ago

This is by design. When you select a radio button, it sets the value of the data to the string value of input. So if it let you initialize selection based on an integer data value, then on selecting another radio button then returning to the first one, you will in fact have changed the data from an integer to the corresponding string. By using strict comparison and requiring converters we have more consistent behavior without subtle indirect side effects which can be difficult to understand or debug.

See the discussion here https://github.com/BorisMoore/jsviews/issues/361.

So yes, using converters is the recommendation. That way your data will still be an integer after selection.

alexx-grand commented 7 years ago

Ok. Thank you for explanation.

BorisMoore commented 7 years ago

BTW I added an additional note to the documentation - see "Data-linking radio buttons to integer variables" at the end of this section: http://www.jsviews.com/#jsvradiogrouptag.