Skip to content

Instantly share code, notes, and snippets.

@joseph-montanez
Created July 21, 2016 19:46
Show Gist options
  • Save joseph-montanez/52c24944ed862cd5791b65032a2b0239 to your computer and use it in GitHub Desktop.
Save joseph-montanez/52c24944ed862cd5791b65032a2b0239 to your computer and use it in GitHub Desktop.
RiotJS 04 - How To Share Data Between Components
<checkboxfield>
<label><input type="checkbox" name="{ name }" checked="{ checked }" value="">{ label }</label>
<br>
<script type="text/javascript">
this.name = opts.name || '';
this.label = opts.label || '';
this.checked = opts.checked || '';
</script>
</checkboxfield>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RiotJS Demo</title>
<script type="riot/tag" src="textboxfield.html"></script>
<script type="riot/tag" src="checkboxfield.html"></script>
<script src="//cdn.jsdelivr.net/riot/2.5/riot+compiler.min.js"></script>
</head>
<body>
<form>
<textboxfield name="first_name" label="First Name"></textboxfield>
<textboxfield name="last_name" label="Last Name"></textboxfield>
<checkboxfield name="has_middle_name" label="Has Middle Name" checked="true"></checkboxfield>
<textboxfield name="middle_name" label="Middle Name"></textboxfield>
</form>
<script type="text/javascript">
riot.mount('*');
</script>
</body>
</html>
<textboxfield>
<style type="text/css">
.error { color:darkred; font-weight: bold; }
</style>
<label>{ label } <input type="text" name="{ name }" value="{ value }"></label>
<div if="{ error.length > 0 }" class="error">{ error }</div>
<br>
<script type="text/javascript">
this.name = opts.name || '';
this.value = opts.value || '';
this.label = opts.label || '';
this.error = opts.error || '';
</script>
</textboxfield>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment