Uncaught TypeError on getQueuedFiles() method used with Dropzone.js - dropzone.js

I'm using Dropzone.js. It works fine until I use getQueuedFiles() method. Not sure what's wrong with my coding.
This is how I tried to get the queued files.
var test = myDropzone.getQueuedFiles();
and it doesn't work.
Here is my code.
Dropzone.autoDiscover = false;
$(function ()
{
var myDropzone =
$('#inputImage').dropzone({
autoProcessQueue: false,
url: './images'
});
var test = myDropzone.getQueuedFiles();
console.log(test);
});
Then I got this error:
"Uncaught TypeError: myDropzone.getQueuedFiles is not a function"
Can anyone help? Thank you.

Okay. I've figured out.
var myDropzone = new Dropzone('#inputImage', {url: './images'});
Then, it works!

Related

Mocha beforeEach not running

I have seen lots of questions about this but all of the fixes simply does not work with my code.
What am I doing wrong? My beforeEach doesnt get executed.
This is the unit test code:
var assert = require('assert');
var environmentConfiguration;
var fs = require('fs');
var expect = require('chai').expect;
describe('environmentConfiguration', function() {
beforeEach('some description', function() {
console.log("hello")
});
describe('#configFile null configFile', function() {
var result = environmentConfiguration.load(null)
var expectedConfiguration = JSON.parse(fs.readFileSync('./ISPRemotingService.config.json'));
it('should return current ISP environment configuration', function() {
assert(result, expectedConfiguration);
});
});
});
I have also applied simpler versions from Mocha's documentation and beforeEach doesn't gets executed.
Another exception was blocking the unit tests to even reach there. My bad

How to post information in CasperJS

The following is the html I wanna tackle with.
I wanna post a query and see the weather reports for that city. I tried my codes:
var casper = require('casper').create();
var utils = require('utils');
casper.start('http://www.weather.com.cn/weather1d/101210101.shtml');
casper.waitForSelector('input', function()
{
this.fillXPath('div.search clearfix',{'//input[#id="txtZip"]':'shijiazhuang'},true);
});
casper.then(function()
{
utils.dump(this.getTitle());
});
casper.run();
It did not print the web paeg title on the console. I also tried this:
casper.waitForSelector('input', function()
{
this.fillSelectors('div.search clearfix',{'input[id="txtZip"]':'shijiazhuang'},true);
});
}
);
I did not get any web page title also. I got quite confused and did not what I had done wrong. Besides, it seems that this.fill method only tackles with name attributes to post information on CasperJS's official website. I need your help.
CasperJS script:
var casper = require('casper').create(), utils = require('utils');
casper
.start('http://www.weather.com.cn/weather1d/101210101.shtml',function(){
this
.wait(3000,function(){
this.capture('search.png');
utils.dump(this.getTitle());
})
.evaluate(function(){
document.getElementById('txtZip').value='shijiazhuang';
document.querySelector('input[type="button"]').click();
})
})
.run();
Result:
"【石家庄天气】石家庄今天天气预报,今天,今天天气,7天,15天天气预报,天气预报一周,天气预报15天查询"
search.png
You are doing it correct, you only have to modify your script a little bit.
Just modify the selector of the input field the actual don't seems to work, then you should get the correct result.
"this.fillXPath" only fills up the form and don't post it.
...
// fill the form
casper.waitForSelector('input', function() {
this.fillXPath('#txtZip', {
'//input[#id="txtZip"]': 'shijiazhuang'
}, true);
});
// trigger - post the form
casper.then(function() {
this.click('#btnZip');
});
// i can't speak chinese - wait for some specific change on this page
casper.wait(5000);
// take a screenshot of it
casper.then(function() {
this.capture("shijiazhuang_weather.png");
});
...

Submodule becoming "undefined" in Backbone.Marionette app

I'm making a Marionette app for uploading files and I'm at the very beginning of it. To start things off, I will show you the files I'm working with:
upload_view.js
AppManager.module("PrimaryApp.Upload", function(Upload, AppManager, Backbone, Marionette, $, _){
Upload.UploadPage = Marionette.ItemView.extend({
template: "#upload-template"
});
});
upload_controller.js
AppManager.module("PrimaryApp.Upload", function(Upload, AppManager, Backbone, Marionette, $, _){
Upload.Controller = {
show: function(){
var uploadView = new Upload.UploadPage();
AppManager.regions.primary.show(uploadView);
},
};
});
app.js
var AppManager = new Marionette.Application();
AppManager.on("before:start", function() {
var RegionContainer = Marionette.LayoutView.extend({
el: "#app-container",
regions: {
primary: "#primary-region",
secondary: "#secondary-region",
header: "#header-region"
}
});
AppManager.regions = new RegionContainer();
});
AppManager.on("start", function(){
console.log(AppManager);
AppManager.PrimaryApp.Upload.Controller.show();
})
AppManager.start();
When running this application in a browser I get this error:
Uncaught TypeError: Cannot read property 'Upload' of undefined
For this line of code in app.js:
AppManager.PrimaryApp.Upload.Controller.show();
However, when I output AppManager to the console I get this:
Which shows that AppManager.PrimaryApp is indeed defined and contains all the submodules needed. Any ideas why my AppManager.PrimaryApp is undefined when called as a function, but then is defined when outputted to the console?
Figured out what was wrong!
AppManager.start();
Was in the wrong place and tried to run before AppManager.PrimaryApp was defined. However,
console.log(AppManager);
was somehow called after AppManager.PrimaryApp was defined resulting in a correct output. A simple move of my start() function fixed the order of things.

Referenceerror: data is undefined

I'm trying to make a firefox addon that uses contentscript to inject a .js file in a certain page. Most of it works but i keep getting this weird error.
main.js
var pageMod = require("sdk/page-mod");
var self = require("sdk/self");
var data = require('sdk/self').data;
pageMod.PageMod({
include: ["http://www.google.com",
"https://ww.google.com"
],
contentScriptFile: data.url("contentscript.js")
});
contentscript.js
var s = document.createElement('script');
s.src = data.url('jquery.js');
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
setTimeout(function(){
var d = document.createElement('script');
d.src = data.url('script.js');
d.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(d);
},100)
the content of script.js is unrelevant, because it doesn't even get executed. The error is in contentscript:2:1 Referenceerror: data is undefined.
Keep in mind it needs to be done this way, the script needs to be able to modify the DOM.
You can't access data.url from the content script, you can only do that from main.js. You could pass the file path and name of the script from main in contentScriptOptions.
Also I'm not sure what you're intending to use this for but if you do include: ["https://www.google.com"] then page-mod will only work on https://www.google.com. include: "[*]" allows all websites etc.

Ajax Upload using valums ajax upload plugin inside a form

i just came across this ajax upload plugin and i wish to use it inside a form as shown in the demo page example 3. For some reason i am not able to make it work. I am not sure what parameters come into the function. For example here is my sample code.
$(document).ready(function(){
var upload = new AjaxUpload('property_i',
{
action: 'submitproperty.php',
autoSubmit: false,
onSubmit : function(file , extension){
return false;
}
});
var upload_data = upload.setData({
'propertytype':'propertytype'
});
});
Now the ID used in the AjaxUpload function should be ID of the or of the Entire form. Also how do i use setData method. Any suggestions or links will be very helpful. Thanks
I got it to work with the following code:
new AjaxUpload('#uploader_button', {
action: 'filename.ashx',
autoSubmit: true,
onSubmit: function(file, ext) {
// --- stuff here
// --- add postdata parameters
this.setData({ id: 1, title: docTitle.val() });
},
onComplete: function(file, response) {
// --- stuff here too
}
});
it doesn't utilize the var but instead adds the custom data params in the onSubmit block. The only other difference is that I haven't wrapped the parameter key in quotes as it seems to serialize correctly. And I'm not using autoSubmit: false , but instead it's true...
The only way I could get this to work with autoSubmit: false is to add this outside any function:
var uploader;
var uploadFile;
then in the AjaxUpload(...
onChange: function(file, response){
uploader = this;
uploadFile = file;
},
then in the function to do the upload:
uploader.setData({session: session});
uploader.submit();
Hope this helps
I'm using uploadify and very useful.
http://www.uploadify.com/

Resources