jquery fileupload.js this._on is not a function error - javascript

_initEventHandlers: function () {
if (this._isXHRUpload(this.options)) {
this._on(this.options.dropZone, {
dragover: this._onDragOver,
drop: this._onDrop,
// event.preventDefault() on dragenter is required for IE10+:
dragenter: this._onDragEnter,
// dragleave is not required, but added for completeness:
dragleave: this._onDragLeave
});
this._on(this.options.pasteZone, {
paste: this._onPaste
});
}
if ($.support.fileInput) {
this._on(this.options.fileInput, {
change: this._onChange
});
}
this code inside Jquery.fileupload.js but throw error:
this._on() is not a function
what can i do?

Related

jquery-resizable - onDrag event not working

I am using the jquery-resizable plugin, and I need to inject some code as soon as users stop dragging the splitter. As soon as I add the onDragEnd event, I am not able to drag the handles anymore! I am using the onDragEnd function as listed on Git. Any idea why I am not able to catch that event?
onDragEnd: function () {
alert();
return false;
});
Fiddle: https://jsfiddle.net/mvg0vdm8/2/
Plugin: https://github.com/RickStrahl/jquery-resizable
You have a syntax error, try this:
onDragEnd: function () {
alert();
return false;
}
Complete script (from your fiddle):
$(document).ready(function() {
$(".panel-left").resizable({
handleSelector: ".splitter",
resizeHeight: false,
onDragEnd: function () {
alert();
return false;
}
});
$(".panel-top").resizable({
handleSelector: ".splitter-horizontal",
resizeWidth: false,
onDragEnd: function () {
alert();
return false;
}
});
});

Using on() with a map

I am trying to refactor my code and decided to re-implement my on events by mapping
Here's what i have:
$('img#sorc').on({
mousemove: function (e) {
alert('test in');
}
}, {
mouseleave: function () {
alert('test out');
}
});
Now mouseleave won't work.
I checked my code x10 and stared at it for so long, what did i miss?
You have additional }, { remove it with ,
$('img#sorc').on({
mousemove: function(e) {
alert('test in');
},
mouseleave: function() {
alert('test out');
}
});

JQuery.autosave bind to events does not work

I'm using https://github.com/nervetattoo/jquery-autosave plugin to add autosave functionality to my forms. I try to bind the events offered by the plugin. But they are not fired or I get the error: Uncaught TypeError: undefined is not a function. Where is my mistake?
Form:
<form id="myform">
<input id="inputtext" type="text" value="test">
</form>
Script:
jQuery(function($) {
$('#myform').autosave({
namespace: "myform",
callbacks: {
data: 'serialize',
scope: 'all',
save: {
method: 'ajax',
options: {
url: '#',
type: 'post'
}
}
}
}).bind('changed.myform', function(event, input){
alert('changed');
},
'saved.myform', function (event) {
alert('saved');
});
});
A example is here: http://jsfiddle.net/smsn95cw/3/
Chaining of event triggers does not work here..
If it's bound in a single call it works,
$('#myform').bind('saved', function() {
console.log("saved"); // not works
});
$('#myform').bind('saved.autosave', function() {
console.log("saved.autosave"); //works
});
$('#myform').bind('save', function() {
console.log("save"); // not works
});
$('#myform').bind('save.autosave', function() {
console.log("save.autosave"); //works
});
$('#myform').bind('changed', function() {
console.log("changed"); // not works
});
$('#myform').bind('changed.autosave', function() {
console.log("changed.autosave"); //works
});

Cutting down JQuery repetitive code

In a Jquery code I've the following situation:
$("#input_field").on('input', function () {
setTimeout(function (e) {
$.post("endpoint.php", $('#main').serialize(), function (response) {
parseRes(response);
});
}, 1);
});
$("#input_field").on("paste", function () {
setTimeout(function (e) {
$.post("endpoint.php", $('#main').serialize(), function (response) {
parseRes(response);
});
}, 1);
});
The only different thing is the event ("input" or "paste").
Is there any way to avoid this kind of repetitions (eg. adding more events to ONE code block)?
Try,
$("#input_field").on('input paste',function() {
setTimeout(function(e) {
$.post("endpoint.php", $('#main').serialize(), function (response) {
parseRes(response);
});
}, 1);
});
Please read here to know more about .on()
From the documentation:
.on( events [, selector ] [, data ], handler(eventObject) )
events: One or more space-separated event types and
optional namespaces, such as "click" or "keydown.myPlugin".
This means your code simply boils down to:
$("#input_field").on('input paste',function() {
// ...
});

Jquery validation stopped working

here's my call to the validate function. Everything works fine with this code.
$('#createForm').validate(function () {
});
But when I try to modify it a bit, the whole validation stop working:
$('#createForm').validate(function () {
errorPlacement: function(error, element) {
error.insertAfter(element);
},
debug:true
});
Any Idea?
you shouldn't have function() in there. change it to:
$('#createForm').validate(
{
errorPlacement: function(error, element) {
error.insertAfter(element);
},
debug:true
}
);
the stuff in the { } is the options. it's not a function :)
just remove function () in .validate(function () { and that should work...

Categories