Created
November 29, 2016 15:42
-
-
Save klhall1987/a39c3825eda0629ab593995e29f44763 to your computer and use it in GitHub Desktop.
This Gist shows how to use JS to get and modify form data.
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
jQuery( document ).ready( function() { | |
var runCustomJS = Marionette.Object.extend( { | |
initialize: function() { | |
this.listenTo( Backbone.Radio.channel( 'form' ), 'render:view', this.editFieldData ); | |
}, | |
/* | |
* In this function you can do things like: | |
* modify the form data | |
* modify field data | |
* etc. | |
*/ | |
editFieldData: function( view ) { | |
//Get form data. | |
var formModel = view.model; | |
var fieldCollection = formModel.get( 'fields' ); | |
//To update a specific field by key. | |
var emailField = fieldCollection.findWhere( { key: 'email' } ); | |
emailField.set( 'value', 'someValue' ); | |
//Tell the field to re-render. | |
emailField.trigger( 'reRender' ); | |
//Update a field by ID. | |
var htmlField = fieldCollection.get( 12 ); | |
htmlField.set( 'value', 'someValue' ); | |
//Tell the field to re-render. | |
htmlField.trigger( 'reRender' ); | |
} | |
}); | |
new runCustomJS(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment