Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Created February 4, 2014 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisbuttery/8796421 to your computer and use it in GitHub Desktop.
Save chrisbuttery/8796421 to your computer and use it in GitHub Desktop.
Personal Details - component
var PersonalDetailsForm = require('personal-details');
var personalDetailsFormEl = document.querySelector('.js-personal-details-form');
if(personalDetailsFormEl) {
var data = document.querySelector('.js-personal-details-data');
new PersonalDetailsForm(personalDetailsFormEl, data);
}
<script type="text/json" class="js-personal-details-data">
@Html.Raw(Model.ToJson())
</script>
<form class="js-personal-details-form">...</form>
var reactive = require('reactive');
var Observable = require('observable');
var Form = require('form');
function PersonalDetailsForm(el, data) {
this.el = el;
this.model = new Observable();
this.model.set(JSON.parse(data.innerHTML));
this.bindings = reactive(this.el, this.model, this);
this.form = new Form(this.el);
}
module.exports = PersonalDetailsForm;
@anthonyshort
Copy link

https://gist.github.com/chrisbuttery/8796421#file-personal-details-index-js-L8

I'd probably parse it in boot so the view just gets an object of data.

@anthonyshort
Copy link

But other than that, looks smokin'!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment