Skip to content

Instantly share code, notes, and snippets.

@zachskaggs
Created October 5, 2016 20:14
Show Gist options
  • Save zachskaggs/e1a58abcb52f24bf80ae4eac4448f59a to your computer and use it in GitHub Desktop.
Save zachskaggs/e1a58abcb52f24bf80ae4eac4448f59a to your computer and use it in GitHub Desktop.
// Create a new object for custom code.
var myCustomFieldController = Marionette.Object.extend( {
initialize: function() {
this.listenTo( Backbone.Radio.channel( 'app' ), 'after:loadControllers', this.changeValue );
},
changeValue: function() {
var model = Backbone.Radio.channel( 'form-109' ).request( 'get:fieldByKey', 'textbox' ); //use your form number in place of '109' here. Replace 'textbox' with your field key. Field key must be unique per form and page, should a page contain multiple forms
if ( model ) {
model.set( 'value', 'foo' ); // Update the value. Replace 'foo' with your value
}
}
});
jQuery( document ).ready( function() {
new myCustomFieldController();
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment