mavo icon indicating copy to clipboard operation
mavo copied to clipboard

collection of input type radio doesn't save data

Open GalinhaLX opened this issue 3 years ago • 3 comments

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

GalinhaLX avatar Jan 14 '22 07:01 GalinhaLX

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?

GalinhaLX avatar Jan 14 '22 08:01 GalinhaLX

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 same property 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.

LeaVerou avatar Jan 14 '22 11:01 LeaVerou

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 values, 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.

DmitrySharabin avatar Jan 14 '22 16:01 DmitrySharabin