Skip to content

Instantly share code, notes, and snippets.

@nickh
Created May 4, 2011 18:14
Show Gist options
  • Save nickh/955699 to your computer and use it in GitHub Desktop.
Save nickh/955699 to your computer and use it in GitHub Desktop.
CKEditor + Backbone: play nicer
diff --git a/public/javascripts/app/views/messages/message.js b/public/javascrip
index ae6e29f..f6f5534 100644
--- a/public/javascripts/app/views/messages/message.js
+++ b/public/javascripts/app/views/messages/message.js
@@ -21,6 +21,10 @@ VR.Views.Messages.Components.Base = VR.Views.Base.extend({
},
validate: function( silent ) {
+ if ( this.beforeValidate ) {
+ this.beforeValidate();
+ };
+
var view = this;
var $required_inputs = this.$j('.required input, .required textarea');
var all_passed_validation = _( $required_inputs.map( function() {
@@ -218,6 +222,7 @@ VR.Views.Messages.Components.Editor = VR.Views.Messages.Comp
};
var view = this;
+
this.els.$html_editor_link.click( function( e ) {
e.preventDefault();
view.els.$html_editor.show();
@@ -246,6 +251,12 @@ VR.Views.Messages.Components.Editor = VR.Views.Messages.Com
this.els.$text_body_field.attr( 'disabled', this.model.get( 'text_auto_gene
},
+ // See aforementioned CKEditor/event fail; ensure that content has been synce
+ // before trying to validate content.
+ beforeValidate: function(){
+ this.syncHtmlBody();
+ },
+
beforeSave: function(){
this.syncHtmlBody();
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment