How to use fwEvents in JavaScript?
Hi
Regarding documentation, i can attach custom event listener to any Option, for examplehttp://manual.unyson.io/en/latest/options/built-in/image-picker.html i want "on click" event for Image Picker option
i register custom JS script
wp_register_script( 'my-backend', get_template_directory_uri() . '/js/admin/admin.js' );
wp_enqueue_script( 'my-backend', array( 'fw-events', 'jquery' ) );
then in JavaScript
jQuery.noConflict()( function($){
"use strict";
/** Image Picker On Change, not working **/
fwEvents.on('fw:option-type:image-picker:clicked', function( e, data ) {
console.log('it works!');
});
});
when i click on Image Picker, i don't see "it works" in my console
Could you tell me, how to use FW Events? Thank you
- Try to enable debug by typing
fwEvents.debug(true)in one of your JS files - Check JavaScript console in Chrome and see if your event listeners are added and if the events are triggered correctly.
Good luck.
@andreiglingeanu events are in the option js , they don't trigger
https://github.com/ThemeFuse/Unyson/blob/master/framework/includes/option-types/image-picker/static/js/scripts.js#L21
@andreiglingeanu thanks, but there is no errors in the console
@danyj Then you have to listen for events on the option type DOM element itself. Or you are welcome to come up with a pull request that will trigger an event with fwEvents.
@WPJobs
$('.fw-option-type-image-picker').on('fw:option-type:image-picker:clicked', function( e, data ) {
console.log('it works!');
});
http://prntscr.com/cmwh28
@andreiglingeanu , just saw that https://github.com/ThemeFuse/Unyson/blob/master/framework/includes/option-types/image-picker/static/js/scripts.js#L2
@andreiglingeanu, @danyj, thank you, i figured it out, correct code to use:
fwEvents.on('fw:options:init', function (data) {
$('.fw-option-type-image-picker').on('fw:option-type:image-picker:changed', function( e, data ) {
console.log('image picker changed!');
});
});
p.s. it is good to add this code in documentation :) thank you again for the fast support!
(function($, fwe) {
fwe.on('fw:options:init', function(data) {
$('.fw-option-type-image-picker').on('fw:option-type:image-picker:changed', function(e, data) {
console.log('image picker changed!');
});
});
})(jQuery, fwEvents);
either way , it works ok
Hi the code above apply for text option ?
(function($, fwe) {
fwe.on('fw:options:init', function(data) {
$( '.my-input' ).on('fw:option-type:text:changed', function(e, data) {
console.log( 'not print!' );
});
});
})(jQuery, fwEvents);
not works for me