JSFiddle - React, Tailwind, and code Playground
by rich_harris
HTML
<script src="http://cdn.ractivejs.org/edge/ractive.js"></script>
<main></main>
<p>Input name (should be <code id='expected'></code>): <code id='actual'></code></p>
<script id='template' type='text/ractive'>
<button on-click='toggleStep'>toggle step</button>
{{#with steps[current] }}
<h3>{{name}}</h3>
{{#each options}}
<input type='radio' name='{{~/selected[name]}}' value='{{this}}'/> {{this}}
{{/each}}
{{/with}}
<p><code>selected: {{ JSON.stringify(selected) }}</code></p>
</script>
CSS
body {
font-family: 'Helvetica Neue', arial, sans-serif;
font-weight: 200;
color: #353535;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 200;
}
code {
background-color: #eee;
border: #ddd;
padding: 0.3em;
}
JavaScript
var ractive = new Ractive({
el: 'main',
template: '#template',
data: {
steps: [
{ name: 'one', options: [ 'a', 'b' ] },
{ name: 'two', options: [ 'c', 'd' ] }
],
current: 0
}
});
ractive.on( 'toggleStep', function () {
this.set( 'current', this.get( 'current' ) === 1 ? 0 : 1 );
});
ractive.observe( 'current', function ( step ) {
expected.innerHTML = '{{selected.' + this.get( 'steps' )[step].name + '}}';
actual.innerHTML = this.find( 'input' ).name;
}, { defer: true });