Jump to content

ips.utils.form.serializeAsObject on codemirror and ckeditor


BomAle

Recommended Posts

@Rikki @Mark can you or others show me a example to got updated serialized input for javascript ckeditor and codemirror?

I don't see any example here: https://invisionpower.com/4guides/themes-and-customizations/javascript-framework/using-utility-modules/

but I have found some example from streams controller like:

this._formData = ips.utils.form.serializeAsObject( this.scope.find('form'), this._serializeConfig );

where

this._serializeConfig = {
	'stream_date_range[start]': this._serializeDate,
	'stream_date_range[end]': this._serializeDate
};
/**
 * A function which will be passed into the serializeAsObject function so that
 * we can format dates consistently as YYYY-MM-DD. 
 * MUST return a string.
 *
 * @param 		{string} 	name	Name of form field
 * @param 		{string} 	value 	Value of form field as returned by jQuery's serializeArray()
 * @returns 	{string}
 */
_serializeDate: function (name, value) {
	// If we're an HTML5 browser, dates are already in YYYY-MM-DD format, so we can return
	if( ips.utils.time.supportsHTMLDate() ){
		return value;
	}

	var dateObj = ips.utils.time.getDateFromInput( $('input[name=' + ips.utils.css.escapeSelector( name ) + ']') );

	// Nothing if this isn't really a date
	if( !ips.utils.time.isValidDateObj( dateObj ) ){
		return '';
	}

	// Format the date to YYYY-MM-DD
	var month = ( '0' + ( dateObj.getUTCMonth() + 1 ) ).slice( -2 );
	var day = ( '0' + ( dateObj.getUTCDate() ) ).slice( -2 );

	return dateObj.getUTCFullYear() + '-' + month + '-' + day;
}

OR can i trigger some event to get updated before call ips.utils.form.serializeAsObject?

ps I have 4.1.18.2

Link to comment
Share on other sites

solved for ckeditor calling:

try {
	if( !_.isUndefined( CKEDITOR ) && CKEDITOR != null ){
		for( var instance in CKEDITOR.instances ) {
			CKEDITOR.instances[ instance ].updateElement();
		}
	}
} catch (err) { }

also for codemirror with:

ips.ui.form.respond($('#bacalltoactionpopup_template'));

if there is other best solution please report here :bye:

Link to comment
Share on other sites

updated with:

// trigger to interact with form widget instead call ips.ui.form.respond($('#bacalltoactionpopup_template'));
$(document).trigger('contentChange', ['#bacalltoactionpopup_template']);
try {
	if( !_.isUndefined( CKEDITOR ) && CKEDITOR != null ){
		for( var instance in CKEDITOR.instances ) {
			CKEDITOR.instances[ instance ].updateElement();
		}
	}
} catch (err) { }

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...