Skip to content

Instantly share code, notes, and snippets.

@kstover
Created October 26, 2016 18:01
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 kstover/de626edd24568aed04f236722cca31c6 to your computer and use it in GitHub Desktop.
Save kstover/de626edd24568aed04f236722cca31c6 to your computer and use it in GitHub Desktop.
// Create a new object for custom validation of a custom field.
var mySubmitController = Marionette.Object.extend( {
initialize: function() {
this.listenTo( Backbone.Radio.channel( 'field-4', 'change:field', this.nameChange ) );
},
nameChange: function( el, model ) {
// Split your model value
var value = model.get( 'value' );
var firstNameValue = ''// First name logic
var lastNameValue = ''// Last name logic
// Get our first name model and update the value where 5 is the field ID
var firstNameModel = Backbone.Radio.channel( 'fields' ).request( 'get:field', 5 );
firstNameModel.set( 'value', firstNameValue );
// Get our last name model and update the value where 6 is the field ID
var lastNameModel = Backbone.Radio.channel( 'fields' ).request( 'get:field', 6 );
lastNameModel.set( 'value', lastNameValue );
},
});
// On Document Ready...
jQuery( document ).ready( function( $ ) {
// Instantiate our custom field's controller, defined above.
new mySubmitController();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment