mavo
mavo copied to clipboard
collection of input type radio doesn't save data
While trying to do a rating star input element (https://codepen.io/GATIGA/pen/NWaeXoy
I came with this issue: collection of input type radio, are not saving data
separate test here: https://codepen.io/GATIGA/pen/XWeoPdB
in fact , it saves value, only if I add property name like name="[$index]"
<div mv-multiple property="radios">
<label> (name set with expression) value SAVED:
<input type="radio" property="radio" name="[$index]"/>
</label>
</div>
isn't mavo supposed to set a name automatically?
There are several issues at play here, though you may well have found a bug too:
- Radios are a bit weird in HTML, and as a result they're a bit weird in Mavo. They're the only HTML element whose value is not self-contained, but depends on other elements that can be anywhere in the page. Mavo has code to handle this, but expects the
property
attribute to only be present on one radio in the group, not all of them. In Mavo, when you add the sameproperty
attribute on multiple elements, it creates an implicit collection, which is not the handling you want here. - In general it's inadvisable to have radios without name and value properties
@DmitrySharabin could you check if there's any actual bug here? I can't quite tell from the testcase, due to the issues above.
If I get everything correctly, here is the reduced testcase: https://codepen.io/dmitrysharabin/pen/ExwGqRM?editors=1000
It looks like input[type=checkbox][property]
inside collections should be treated as an edge case. As expected, Mavo created an implicit collection of these elements, and since they share the same name
and have value
s, the UI is correct. However, if the stored value doesn't correspond to the first radio button inside a group of buttons, Mavo doesn't know how to set the corresponding property.