Does Javascript accept nested IF statements coming from Progress 4GL?
This piece of code below is placed inside the document ready function, is this acceptable in javascript?
When the pdf appears, it shows nothing.. :(
<!--WSS IF get-value('action') = 'print' then DO: -->
<!--WSS IF get-value('action') = 'go' then DO: -->
newPopup("print_preview.html?win=pdf&programname=pdf_sample2.p",1250,1250);
<!--WSS END. -->
<!--WSS ELSE DO: -->
newPopup("print_preview.html?win=pdf&programname=pdf_sample.p",1250,1250);
<!--WSS END. -->
<!--WSS END. -->
These two lines:
<!--WSS IF get-value('action') = 'print' then DO: -->
<!--WSS IF get-value('action') = 'go' then DO: -->
Implies that the parameter "action" must be both 'print' and 'go' for this line to run:
newPopup("print_preview.html?win=pdf&programname=pdf_sample2.p",1250,1250);
That will of course never happen (action can only have one exact value). If "action" has the value 'print' the second popupscript will be called.
You have to keep in mind what is happening on serverside (everything WebSpeed related) and what happens on clientside (HTML, JavaScript, CSS).
Look at the rendered HTML-code in your browser. Does it look OK? Also: do you get javascript errors in the console? These are basic HTML/JavaScript debugging steps to take.
Did you perhaps intend to code something like this:
<!--WSS IF get-value('action') = 'print' then DO: -->
newPopup("print_preview.html?win=pdf&programname=pdf_sample2.p",1250,1250);
<!--WSS ELSE IF get-value('action') = 'go' then DO: -->
newPopup("print_preview.html?win=pdf&programname=pdf_sample.p",1250,1250);
<!--WSS END. -->
Related
Using the R's tmap package in "view" mode, here I have R pseudocode that generates an interactive world map, and adds an info-button that shows an alert using javascript.
# this is pseudocode - providing real data would be too much work
lf <- tmap_leaflet(tm_world) %>%
setView(2.2945, 0, zoom=2) %>%
addEasyButton(
button = easyButton(
icon = 'fa-warning',
onClick = JS('function(btn, map){ alert("At very high zoom levels,\\nsite locations are approximate\\ndue to various issues."); }')
)
)
print(lf)
Now when print.tmap() and save_tmap() are called, they generate a complex HTML page with lots of javascript base64-encoded inside the page.
I want to include some of my javascript snippets (onLoad handlers, AMD modules) that end up as script tags in the <head> or <footer> elements, unlike the onClick handler of the easyButton).
How can I do that without editing the generated file manually after saving? I want to do this from within R.
I would hide an html element when a condition occurs.
I try to implement this code in coffeescript:
if byName == username
document.#prv-btn.style.display = 'none'
I have already tried this code but don't run.
The element #prv-btn is my html element. In my page i have some users and for each of them i have this #prv-btn. For example if i have ten users, i have ten #prv-btn, but only one i want that i see, each user see the button near his name.
How can I do?
There are a couple of issues:
You need to indent the body of if clauses in CoffeeScript.
You need to use getElementById() to actually select the button by its ID.
Also, I recommend using jQuery for DOM work such as this. It works just fine with the compiled CoffeeScript.
Code:
if byName == username
document.getElementById("prv-btn").style.display = 'none'
Here is a link to a jsFiddle that I made for this: http://jsfiddle.net/jonathanporta/tw3nn/1/
I want the user to be able to select the contents of a element by clicking it once. The code would look like this:
<div onclick="this.xyz()">...</div>
The question is: what method goes where I wrote xyz? I've searched for things like "DOM select object," but the answer is a needle hidden in a haystack of irrelevant hits (or not).
Basically you'd want:
<div onclick="var contents = this.innerText;">foo bar</div>
which would set contents equal to foo bar. Of course, this isn't exactly cross-platform compatible. Firefox expects .textContent instead of .innerText. If you're not opposed to using jquery, then
<div onclick="var contents = $(this).text()">foo bar</div>
would do just as well and be cross-platform.
I have a form in a module that I want to appear in a modal window. Depending on the id the window may be blank, or if it does show any content all classes and ids are removed, so I can't validate or style the form.
Truncated Code:
...
<div id="feedback">
<div class="feedbackinner">
<!-- form module -->
<div id="contact-wrapper">
<!--form elements with ids and classes-->
</div>
<!-- end module -->
</div><!-- end .feedbackinner -->
</div><!-- end #feedback -->
This triggers the modal window without any ids or classes (using Firefox Web Developer outline current elements):
Click for ugly unstyled form that won't validate
This triggers a blank modal window:
Click if you like staring at a blank white box
So most importantly how do I keep all the ids and classes inside the modal window, and why won't calling the parent div work?
( As a work around I moved the form to a component view then called it using handler: 'iframe' instead of clone. I still want to know what's going on with the modal window. )
Thanks!
not seen the code but implications of using Element.clone on an element are apparent. By nature of HTML, id is meant to be unique. This means you are not really supposed to have more than one element with the same id injected into the DOM at the same time.
MooTools mirrors the sentiment correctly by implicitly removing the id from any element it creates a clone of:
https://github.com/mootools/mootools-core/blob/master/Source/Element/Element.js#L860
the .clone method accepts optional arguments which allow you to override stuff:
clone: function(contents, keepid){ - see http://mootools.net/docs/core/Element/Element#Element:clone as well.
cloned elements also lose all the events you may have assigned to them (but cloneEvents can help with that).
I would recommend looking at the squeezebox implementation and double check that the clone is implemented in the intended way. A better practice may be to adopt and re-attach the elements instead - or to copy the whole innerHTML (though this will once again cause non-delegated events to fail).
I am new to watir, and (believe me) I tried all the options that are avaliable here for adding wait and assert but have not been successful in doing so.
Here's a brief description of what I'm trying to do and appreciate your help.
I log into my website
I login using userid/password and hit click button.
I want watir to wait until next page is loaded
I want to do some assert to verify the login was successful.
My step 3 and step 4 are failing with the error element not found.
If I login manually and login is successful, I see text Hello,username at the top of the second page and this is what I've been trying to key off of but not having any success. It could be something very simple, but since I'm new to watir, I'm unable to figure it out.
Here are all the commands I tried:
$b.button(:id, 'usernameLogfaceinButton').click
#$b.wait_until($b.text.include?("Hello"))
#($b.text.include?("Hello")).wait_until_present
#$b.text_field(:text, "Hello").wait_until_present
if $b.text.include? "Hello"
puts "Test Passed. Found the test string: Hello- Actual Results match Expected Results."
else
puts "Test Failed! Could not find: Hello"
end
HTML on Page:
<body id="myAccounts" class="cardholderLayout ">
<div id="content">
<div id="navigationContainer">
<div id="headerNavigationMenu" class="innerContents">
<div class="logo"><img alt="xxx" src="/images/xxx.png?xxxxxxxx"></div>
<ul class="menu">
<li class="menuItem">
Hello, Bob
I hope someone can help me or point me in the right direction.
Try:
$b.link(:text => /^Hello/).wait_until_present
Notice that:
It is $b.link instead of $b.text_field. The method needs to match the type of element you are looking for.
The text in the locator is /^Hello/ instead of "Hello". If you pass a string (ie "Hello", watir will look for an element where the text exactly matches. If you want to do a partial text match, then you need to use a regular expression. The expression /^Hello/ says to find a text starting with "Hello".