How to make swfupload setPostParams work in firefox? - javascript

I want to set some params in my swfupload when some links are clicked, so i did something like this:
swfu.setPostParams({"PHPSESSID": swfu.settings.post_params.PHPSESSID, "tutorial": tutorial, "step": nr});
(this is a tutorial editor and i want to know to which step the file belongs to)
The postparams in the DOM is changed, but I can't find them in the $_POST.
Some flash versions have problems with sending stuff in POST, so I added the following line to my swfupload setup:
use_query_string: true,
Now i get the params in $_GET, but no luck there either: i still get the original params.
In IE it works just fine. Any ideas?

I've just had a very similar problem - I had post_params set in the initialization of the swf object and it was there to grab values of hidden inputs on my page.. but the values were always the defaults if I changed them.
I moved that bit of code to an uploadStart handler (fired on "upload_start_handler") - then something like this inside that:
value1 is an input box, value2 is a checkbox - and I'm getting the values with jQuery.
this.swf.setPostParams({
value1: $('#value1').val(),
value2: $('#value2').is(':checked')
});
Works a treat - the values are now populated when the flash uploader hits my back end script!

Related

jQuery ajax parameter value pulled dynamically

Wondering if there is someway to do this without using a timeout.
Right now I have an ajax request that pulls in a token via an external js. I don't have full control over this script as its provided by a 3rd party.
So it basically does an ajax request and passes me back a token vaule. I then take that value and update a form input with it.
My problem is the form submits before it has time to fully get value, hence the value is never passed.
I have some responses to work with that this 3rd party script provides, right now I am doing something like.
resonseData is passed back to me from this script..
if(responseData.dataValue !='') {
$('[name=payment_token]').val(responseData.dataValue, function(){
$("#userPaymentUpdate").submit();
});
}
^ The problem is the form submits before it has time to update the $('[name=payment_token]').val()
Is there anyway way round this aside for putting a timeout in? I thought by adding a callback like above would solve it, but apparently it doesn't.
I also have event.preventDefault(); on the form click handler, but when thats enable the 3rd party script wont execute at all. So basically need to only submit the form if that payment_token value has been updated.
If I'm reading this correctly, it looks more like an issue of order. responseData.dataValue has the value, otherwise that if condition wouldn't have processed.
Your code should look something like this:
if(responseData.dataValue !='') {
$('input[name=payment_token]').val(responseData.dataValue); /* I'm guessing you're using a hidden field for the payment token. */
$("#userPaymentUpdate").submit(); /* at this point, the value will have already been assigned. */
}

Changing the value of a variable through user input and re-using it on a different page

First I would like to say that I searched and found plenty of answers and even tried a couple (more than...) but to no avail! The error is probably mine but it is time to turn to SO and ask.
Problem description: I have a variable that I want to change the value through the user input (click on btn). As soon as the user chooses the btn it will navigate to a different page that will use the result of the variable to perform certain actions. My issue is that if I alert on my 1st page I get the value being passed by the btn... But on the second page I only get "undefined"
I think it has to do with variable scope and the fact that (I think it works that way anyway) even a window.var will be deleted/purged in a different window.
Anyway, the code is something like this (on the 1st page/file):
var somAlvo;
$('#omissL').click(function(){
somAlvo = 'l';
window.location.href='index_ProofOfConcept_nivel1.html';
});
And on the "receiving end" I have the following code
<head>
...
<script type="text/javascript" src="testForm_javascript.js"></script>
to "import" the js file with the variable and:
var processo = somAlvo;
alert(processo);
I tried declaring window, not using var inside the function and so on...
This is a proof of Concept for a project in my local University, where I'm working as a research assistant (so, this is not homework ;) )
Thanks for any help/hints...
You are right in that when you navigate to another page, the entire JavaScript runtime is reset and all variables lost.
To preserve a value across page loads you have two options:
Include it as part of a query string when navigating to the new page.
Set a cookie.
You may also want to look into loading the new content through an AJAX call and replacing what is displayed. This way you won't reload the entire page which won't cause the JavaScript runtime to be reset.

How to identify a hidden file element in selenium webdriver

Team,
I am trying to automate a file upload functionality but webdriver doesn't recognize the file object. Here is the thing:
The file object is in a modalbox (xpath is of the modal box is //*[#id='modalBoxBody']/div[1]). The type and name of the file object are file and url respectively.
When i see the html content, there are two objects with the same attributes. One of them is visible and another is invisible. But the hierarchy they belong to are different. So I am using the hierarchy where the element is visible.
Following is my code. I have tried all possible solutions provided in the stackoverflow (as much as I could search), but nothing worked. Commented out sections mean that they too are tried and failed.
wbdv.findElement(By.xpath("//*[#id='left-container']/div[4]/ul/li/ul/li[2]/a")).click();
wbdv.switchTo().activeElement();
System.out.println(wbdv.findElement(By.xpath("//*[#id='modalBoxBody']/div[1]")).isDisplayed()); **//This returns true**
List<WebElement> we = wbdv.findElement(By.xpath("//*[#id='modalBoxBody']/div[1]")).findElement(By.className("modalBoxBodyContent")).findElements(By.name("url")); **//There is only one element named url in this hierarchy**
System.out.println(we.isEmpty()); //This returns false meaning it got the element named url
//((JavascriptExecutor) wbdv).executeScript("document.getElementsByName('url')[0].style.display='block';"); **//This didn't work**
for(WebElement ele: we){
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) wbdv).executeScript(js, ele);
System.out.println(ele.isDisplayed()); **//This returns FALSE**
System.out.println(ele.isEnabled()); **//This returns TRUE**
System.out.println(ele.isSelected()); **//This returns FALSE**
ele.click(); **//This throws org.openqa.selenium.ElementNotVisibleException exception**
}
Now, if you look at the 3 methods above, it seems that the element is NOT displayed, NOT selected but IS enabled. So when it is not displayed, selenium cannot identify it. The java script to make it visible also came to no rescue.
Could anyone please help me solve this. It ate my entire day today?
In your last example, it looks to me like you have the right idea with using the 'style.visibility' tag. Another thing that I would recommend trying is using "ExpectedConditions.visibilityOfElementLocatedBy" method. Usually I use "presenceOfElementLocatedBy", but if you are talking about the css visibility property, I think using "visibilityOfElementLocatedBy" is the way to go. I think what might be happening for you is that you need the wait condition on the element object you are trying to get a hold of and the "ExpectedCondtions" method should give you what you need. I see that you have tried a few things but you haven't listed using a Wait condition. No guarantees, but you should try it:
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath(".//whatever")))

Dojo Gridx programattic refresh shows no data

I am trying to create a programmatic filter. I have a dijit.tree and a dojo gridx using the same source on a jsp. When user clicks the tree node, I want to use the node as a filter and show all rows matching it in the gridx
This is my code I have now for the onClick event of the dijit tree node.
var global=this;
treeWidget.onClick = function(item){
global.grid.filter.setFilter(global.grid.filter.grid.filter.moduleClass.or("test"));
Earlier I asked for a sample expression. I went and tried the code above and seems to
refresh the grid but comes back as No items to display. I do have data that match test and if I do a manual filter I see data returning. What am I missing here.
At https://github.com/oria/gridx/wiki/How-to-filter-Gridx-with-any-condition%3F ( see Filter Expressions)
I was able to accomplish the task using the following code in the diji.tree onClick event.
global.grid.filterBar.applyFilter({
conditions: [{
condition: 'contain',
value: 'test'
}]
});
This is a comment rather than an answer, but I can't post comments yet.
Can you post a working snippet of code? That's not complete, as I don't see your store that you're specifying, etc.
I usually do a myinstancename.grid.body.refresh(); to accomplish a proper refresh.

When an Ajax return sets some var to 0, I need to stop all subsequent requests, how within a plugin?

I have a plugin, that fires off for each pagination click on a page. Mind you, that this pagination is front loaded with all of its data. The plugin that I have fires off to retrieve additional information pages on the current paginated view. So, each click instantiates a new plugin - but the same as before (namespace), so it overrides the previous dataSets that set etc..
Anyways, there might be a point where the .ajax url I am hitting is turned off so that the return will hand something like data.isOff = 1 or data.isOff = 0 , etc.. so that I know that the service is suppressed.
Is there a way for any to persist a value from one instantiation to the next of a plugin and if that value is false, then don't instantiate the new plugin call.. ie.. don't hit the init function. just fail out.
I, of course, can set a global var and to it that way, but curious if there is a way I can do it within the plugin so as to not have any outside vars existing.
I tried to put it in my init function, and set it in my options.. just seems that when I try to instantiate a new plugin, all bets from the previous data is gone.

Categories