How to pass parameters to a custom field plugin that invokes a jQuery plugin
How to pass parameters to a custom field plugin that invokes a jQuery plugin
I have a javascript library that needs a start date to fully function.
So far I have the following code that works and successfully invokes the jQuery plugin.
But the plugin can process a start date if it is passed when it is called.
In the jQuery plugin terms that startDate is expected in "conf.startDate.
I have no idea where to set/store the start date.
My custom field type plugin code is:
(function ($, DataTable) {
if (!DataTable.ext.editorFields) {
DataTable.ext.editorFields = {};
}
var Editor = DataTable.Editor;
var _fieldTypes = DataTable.ext.editorFields;
_fieldTypes.recurrenceinput = {
create: function (conf) {
var that = this;
// Create the elements to use for the input
conf._input = $(
'<div id="recurrenceinput1">' +
'<input id="repeat" name="rfc5545" type="text">' +
'</div>')[0];
return conf._input;
},
get: function (conf) {
return $('#repeat', conf._input).val(); //return the field value POST
},
set: function (conf, val) {
$('#repeat', conf._input).val(val); //set the field value from recurrenceinput response
},
};
The jQuery plugin starts like this:
/*
* jQuery plugin implementation
*/
$.fn.recurrenceinput = function (conf) {
if (this.data('recurrenceinput')) {
// plugin already installed
return this.data('recurrenceinput');
}
// "compile" configuration for widget
var config = $.extend({}, tool.conf);
$.extend(config, conf);
$.extend(config, { i18n: LABELS[config.lang], name: this.attr('name') });
alert("configSD=" + config.startDate);
.
.
.
The "alert" shows "configSD=undefined";
BTW, how does one list the elements in an object using Javascript?
Answers
In the Editor plug-in methods, the
conf
object is basically the object that you use forfield
(albeit extended with a few other properties that Editor uses internally).So you can just add your extra properties to that object and then access them through the
conf
object.That's exactly what Editor's build in field types do and the plug-ins available on the Editor site.
Allan