Last active
July 26, 2016 09:48
-
-
Save joseph-montanez/1f51bee78a01208ba2f8e8d92486cfad to your computer and use it in GitHub Desktop.
How to sync data outside a riot component - https://youtu.be/QJPCsydn2Vo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<checkboxfield> | |
<label><input type="checkbox" name="{ name }" checked="{ checked }" value="">{ label }</label> | |
<br> | |
<script type="text/javascript"> | |
var self = this; | |
this.name = opts.name || ''; | |
this.label = opts.label || ''; | |
this.checked = opts.checked || ''; | |
</script> | |
</checkboxfield> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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="https://cdn.jsdelivr.net/riot/2.5/riot+compiler.min.js"></script> | |
</head> | |
<body> | |
<form> | |
<textboxfield name="first_name" label="First Name" value="{ app.first_name }"></textboxfield> | |
<textboxfield name="last_name" label="Last Name"></textboxfield> | |
<checkboxfield name="has_middle_name" label="Has Middle Name" checked="{ app.has_middle_name }"></checkboxfield> | |
<textboxfield name="middle_name" label="Middle Name" hide="{ !app.has_middle_name }"></textboxfield> | |
</form> | |
<script type="text/javascript"> | |
function App() { | |
this.first_name = ''; | |
this.last_name = ''; | |
this.has_middle_name = true; | |
this.middle_name = ''; | |
this.setHasMiddleName = function (checked) { | |
this.has_middle_name = checked; | |
}; | |
this.getHasMiddleName = function () { | |
return this.has_middle_name; | |
} | |
} | |
var app = new App(); | |
riot.mount('*', { app: app }); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<textboxfield hide="{ hide }"> | |
<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"> | |
var self = this; | |
this.name = opts.name || ''; | |
this.value = opts.value || ''; | |
this.label = opts.label || ''; | |
this.error = opts.error || ''; | |
this.hide = opts.hide || false; | |
</script> | |
</textboxfield> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment