I am using the jQuery boilerplate and am trying to call one function from within another function and thought that Proxy might be the way to achieve that. Unfortunately I can't seem to get this to work.
Below is a heavily stripped down version of the code I am using, but you should be able to get the idea. Inside the ajax success
method, I am trying to call the function customSelect
so that I can reapply my select styling on elements created when the ajax is run. Unfortunately I'm unable to get this to work:
;( function( $, window, document, undefined ) {
"use strict";
var pluginName = "serviceFinder",
defaults = {
propertyName: "value"
};
// The actual plugin constructor
function Plugin ( element, options ) {
this._name = pluginName;
this.init();
}
// Avoid Plugin.prototype conflicts
$.extend(Plugin.prototype, {
init: function() {
this.customSelect("lm-service-finder__field--select");
},
/**
* When a user selects a product
*/
selectProduct: function(e){
// Send the ID of the selected product so that we can get the variations for that product.
$.ajax({
type: 'POST',
url: themeVars.ajax,
dataType: 'json',
data: {
'product_id': selectedProductId,
action: 'servicefinder_get_product_attributes' //this is the name of the AJAX method called in WordPress
}, success: function (result) {
$.proxy(Plugin.customSelect);
},
error: function () {
console.log("error");
}
});
},
/**
* Custom select field styling
*/
customSelect: function(selector) {
console.log("Apply select field styling");
},
});
$.fn[ pluginName ] = function( options ) {
return this.each( function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" +
pluginName, new Plugin( this, options ) );
}
} );
};
} )( jQuery, window, document );
I have seen a couple of other similar questions here, but with no answer. Hope someone can assist?