I’m attempting to swap out some radio inputs for button inputs:
So instead of this:
div class="mdl-cell mdl-cell--9-col">
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect rating-radio" for="option-1">
<input type="radio" id="option-1" class="mdl-radio__button" name="options1" value="1" checked />
<span class="mdl-radio__label">Red</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect rating-radio" for="option-2">
<input type="radio" id="option-2" class="mdl-radio__button" name="options1" value="2" />
<span class="mdl-radio__label">Amber</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect rating-radio" for="option-3">
<input type="radio" id="option-3" class="mdl-radio__button" name="options1" value="2" />
<span class="mdl-radio__label">Green</span>
</label>
<label class="mdl-radio mdl-js-radio mdl-js-ripple-effect rating-radio" for="option-4">
<input type="radio" id="option-4" class="mdl-radio__button" name="options1" value="2" />
<span class="mdl-radio__label">Gold</span>
</label>
</div>
I’d like to have something like this:
<div class="mdl-cell mdl-cell--9-col">
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored radio-selected" style="background: red;">Red</button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored radio-unselected" style="background: #FFC200;">Amber</button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored radio-unselected" style="background: green;">Green</button>
<button class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored radio-unselected" style="background: #FFD700;">Gold</button>
</div>
My question is, what’s the best way to define the behaviour of the above in Meteor? (i.e. ensure that only one button is “selected” and automatically apply a CSS class on select/unselect)
I’m also using the autoforms package as well, not sure if that makes it easier/harder.
I’m trying to think if there’s another way to do this - maybe manipulating the DOM to swap out radio elements for buttons? Or is that a bit hacky? I think it might be nicer if we could wrap this in a component in Meteor somehow.