Skip to content

Instantly share code, notes, and snippets.

@markupboy
Created January 18, 2013 16:42
Show Gist options
  • Save markupboy/4565933 to your computer and use it in GitHub Desktop.
Save markupboy/4565933 to your computer and use it in GitHub Desktop.
backbone form helpers
_.extend Backbone.View.prototype,
parse: (objName) ->
_recurse_form = (object, objName) =>
_.each object, (v,k) ->
if v instanceof Object
object[k] = _recurse_form v, "#{objName}[#{k}_attributes]"
else
object[k] = @$("[name=#{objName}[#{k}]]").val()
return object
@model.attributes = _recurse_form @model.attributes, objName
populate: (objName) ->
_recurse_obj = (object, objName) =>
_.each object, (v,k) ->
if v instanceof Object
_recurse_obj v, objName + "#{objName}[#{k}_attributes]"
else if _.isString(v)
@$("[name=#{objName}[#{k}]]").val(v)
_recurse_obj @model.attributes, objName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment