Skip to content

Instantly share code, notes, and snippets.

@deitch
Created September 3, 2013 05:14
Show Gist options
  • Save deitch/6419924 to your computer and use it in GitHub Desktop.
Save deitch/6419924 to your computer and use it in GitHub Desktop.
Backbone with jquery.wizard
NewItemView = Backbone.View.extend({
el: "div#newitm",
events: {
"click input#clicktocreate-button":"createItem"
},
initialize: function() {
var that = this;
this.subitemView = new SubItemView({el:"div#newitem div.item-list"});
this.$el.wizard({
beforeSelect: function(event,state) {
var success;
success = $(this).wizard('state').step.validateAndMarkForm();
return(success);
},
afterSelect: function(event,state) {
$(this).wizard('state').step.find("input").removeAttr("disabled");
}
});
},
render: function() {
// enable any forms, etc
// create/reset subviews to allow editing
this.subitemView.reset();
this.$el.wizard("select",0).show();
},
createItem: function() {
var that = this, form = this.$("form"), w = whoami(), s;
if (form.validateAndMarkForm()) {
// hide the error message
error.hide();
// need to set up the model data as follows:
// 1) serialize the form data - only text and textarea
s = form.serializeHash("[type=text],textarea");
// 2) include only those fields that are relevant to the model
// 3) make sure to include any additional derived elements, e.g. LTR/RTL
s.direction = form.find("[name=summary]").hasClass("rtl") ? "rtl" : "ltr";
// save model
} else {
// show errors on the form
}
// we already handled the form submission
return(false);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment