When I load Jquery from CDN, it is working but the problem is I cant do validation of fields that are defined in rules() method. But when I don't
load custom Jquery version from CDN then validation is working.
Also, I am getting jQuery(...).yiiActiveForm is not a function in the console when I load Jquery from CDN and if I use inbuilt Jquery then no error.
You can use jQuery.noConflict for your second, non-yii jQuery and use another var name instead of $. In this example i use jq
var jq = jQuery.noConflict();
// Do something with jQuery
jq( "div p" ).hide();
// Do something with another library's $()
$( ".content" ).hide();
You can add this line in your template after your tag with jQuery.
<script>var jq = jQuery.noConflict();</script>
If you use an Asset, just load an additional .js script with that line.
Anyway, you should avoid this entirely if you can.
From the documentation:
If for some reason two versions of jQuery are loaded (which is not
recommended), calling $.noConflict( true ) from the second version
will return the globally scoped jQuery variables to those of the first
version.
Using express framework -
I am loading an initial JSON state representation into my template that my react front end will rehydrate its initial state from, but I'm wondering if it is safe to do something like this -
<script type="text/javascript">
window.INIT_DATA = <%- initialState %>
</script>
The output of that if I view the page source might look something like this -
<script type="text/javascript">
window.INIT_DATA = {"recentImages": [ 11342, 11344, 11432 ], "lastOnline": "Yesterday"}
</script>
Is this safe to do? Are there any good practices to follow? Thanks
No, this is not safe. Suppose the initialState contains a string that looks like this:
"hello! </script><script>alert("PWND")</script>"
This will cause the embedded code to run. In other words: if the JSON you're embedding contains any user supplied strings you're opening the door to XSS attacks.
To prevent this, replace </ with <\/, and <!-- with <\!--. In JSON strings \/ and \! will be interpreted as a simple slash or exclamation mark, so this doesn't change the semantics of the JSON, but it will prevent the HTML parser from seeing a closing tag.
I don't see why this wouldn't be safe? However I suggest you don't store the variable in the window object; it is discouraged as the window is a global object.
I try to use:
action.sendKeys("some phrase with a dot, for example: www.google.co.il ");
but when i run the program what the action writes is:
www*google*co*il
the * represent hebrew character.
I can disable this only by disabling the hebrew language in my computer.
I tried to bypass the problem by using JS: set.attribute but it makes a lot of problems and i need something better.
Is there a function similar to sendkeys or a way to fix it?
You can try JavascriptExecuter using below code:
WebElement text= driver.findElement(By.name("q"));
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("arguments[0].value='test input';", text);
Webelement is the textbox where your need to write the value.
Or you can try some copy paste action after clicking into text box.
actions.click();
Refer to this URL for help:
http://www.helloselenium.com/2015/03/how-to-set-string-to-clipboard-data.html
I found out a way to change language during the tests while I solved another problem related to Upload a picture. there is this freeware called AuTOIT that you can use to help you with dialogs on Windows. I wrote a script to push the alt and click shift and my language is changed.
To change the language, I use the line:
Runtime.getRuntime().exec("path_of_script_here/name_of_script_here.exe");
The script was made the following way:
Open a text file.
Inside the file write:
Send ("{ALTDOWN}") ;Hold down Alt
Sleep(100) ;Wait 100 milliseconds
Send("{LSHIFT}{ALTUP}") ;Press Left-Shift and release Alt
Save as .au3 file.
Download and install AUTOIT.
Compile the script and then exe file will be created.
Run the test.
Hope this will help everyone else who encounters this problem. If something is not clear, ask me and I will gladly help.
I'm doing a simple AJAX post request in jQuery to another page on my site to get an XML document response. I'm putting the response into a pre element with syntax highlighting enabled. The response comes through fine (I can alert it), but it isn't being added to thepre element when I attempt to assign it in the handlResponse function with jQuery.
<head>
<script>
...
function handleResponse(response, status)
{
$("#output").text(response);
}
$.post(url, data, handleResponse, "text");
...
</script>
</head>
...
<pre id="output">
</pre>
Just to be clear, the javascript code above is in jQuery's document ready function. Any help would definitely be appreciated.
Three things:
Is the response being passed correctly? Check by doing alert of response from within the function itself.
Is the function being called correctly? Check by having it do an alert unrelated to the response variable (alert("Yo!")).
Is the text being inserted correctly? I can tell it should work, but for sake of full debug, add a ternary like this:
var preText = (response != "") ? response : "The problem is with the reponse";
Try using html instead of text...
$("#output").html(response);
EDIT: If you think escaping is the issue, the following should escape it well enough to display...
response = response.replace(/</g, "<");
$("#output").html(response);
Apparently this is a bad question. I'm using the javascript lib SyntaxHighlighter and had preloaded the syntax highlighting on the pre tag I was attempting to use. My solution was to remove the tag and dynamically create it when the ajax response comes in. This worked well other than the fact that I'm trying to determine how to load the highlighting on a dynamically appended dom element.
Thanks for the responses.
I'd like to be able to do something like this in vim (you can assume v7+ if it helps).
Type in a command like this (or something close)
:inshtml
and have vim dump the following into the current file at the current cursor location
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
</body>
</html>
Can I write a vim function do this is? Is there a better way?
Late to the party, just for future reference, but another way of doing it is to create a command, e.g.
:command Inshtml :normal i your text here^V<ESC>
The you can call it as
:Inshtml
Explanation: the command runs in command mode, and you switch to normal mode with :normal, then to insert mode with 'i', what follows the 'i' is your text and you finish with escape, which is entered as character by entering ^V
It is also possible to add arguments, e.g.
:command -nargs=1 Inshtml :normal i You entered <args>^V<ESC>
where <args> (entered literally as is) will be replaced with the actual arguments, and you call it with
:Inshtml blah
I do that by keeping under my vim folder a set of files which then I insert using the r command (which inserts the contents of a file, at the current location if no line number is passed) from some function:
function! Class()
" ~/vim/cpp/new-class.txt is the path to the template file
r~/vim/cpp/new-class.txt
endfunction
This is very practical - in my opinion - when you want to insert multi-line text. Then you can, for example, map a keyboard shortcut to call your function:
nmap ^N :call Class()<CR>
i have created a new file generate_html.vim in ~/.vim/plugins/
with the following code
"
" <This plugin generates html tags to new html files>
"
autocmd BufNewFile *.html call Generate_html()
function! Generate_html()
call append(0, "<!DOCTYPE HTML>")
call append(1, "<html><head>")
call append(2, " <title></title>")
call append(3, ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />')
call append(4, ' <style type="text/css">')
call append(5, ' </style>')
call append(6, '</head>')
call append(7, '<body>')
call append(8, '</body>')
call append(9, '</html>')
endfunction
this way, everytime I open a new .html file in vim, it prints that text to the new file
Can you define an abbreviation. e.g.
:ab insh 'your html here'
as nothing in the above appears to be parameterised ?
In fact, looking at my VIM configs, I detect a new .html file being loaded thus:
autocmd BufNewFile *.html call GenerateHeader()
and define a function GenerateHeader() to insert my required template (I do the same for Java/Perl etc.).
It's worth getting the Vim Cookbook for this sort of stuff. It's a sound investment.
snippetsEmu
I like to use the snippetsEmu vim plugin to insert code snippets like your.
The advantage of snippetsEmu is that you can specify place holders and jump directly to them in order to insert a value. In your case you could for example add a place holder between the title tags so you can easily add a title to the document when inserting this snippet.
snippetsEmu comes with various snippets (also for HTML) and new snippets can be esaily added.
EDIT
snipMate
Today I revisited my VIM confiugration + installed plugins and found the snipMate plugin, which is IMHO even better than snippetsEmu. snipMate updates just like TextMate all placeholders on the fly.
This should be possible. I use auto-replacement. In my .vimrc I have this line:
iab _perls #!/usr/bin/perl<CR><BS><CR>use strict;<CR>use warnings;<CR>
And whenever I start a Perl script, I just type _perls and hit Enter.
You can use Python (or any other program) if like me you haven't quite grasped vimScript
This guy talks about the vim expression register. Essentially you put something like this in your .vimrc file
:imap <C-j> <C-r>=system('/home/BennyHill/htmlScript.py')<CR>
So that every time in insert mode you press Ctrlj it calls the script htmlScript.py which has something like this in it (NOTE I haven't actually tested this)
#!/usr/bin/env python
import sys
snippet="""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
</body>
</html>"""
sys.stdout.write(snippet)
Then just remember to make the file executable (chmod 0755 /home/BennyHill/htmlScript.py). It might be overkill, but I am far more comfortable with Python than I am with vim's syntax.
You can once copy this text to some ( for example 'a' ) register. And paste it every time you need unless you overwrite register 'a'.
To copy to register a in visual mode: "ay
To paste from register a in normal mode: "ap
To paste from register a in insert mode: a
Or if you have this template already copied you can use
let #a = #*
To put this template to register a.
There are many template expander plugins for vim.
NB: I'm maintaining the fork of muTemplate. Just dump your code into
{rtp}/template/html.template or into $VIMTEMPLATES/html.template. And that's all. If you don't want the snippet to be implicitly loaded when opening a new HTML file, then name the template-file html/whatever.template (instead of html.template), and load it with :MuTemplate html/whatever of with whatever^r<tab> in INSERT mode (in an HTML buffer).
All the path issues, portability issues, etc are already taken care of. And unlike snippetEmu that supports (and somehow expects) several (hard to maintain, IMO) snippets in a same snippets definition file, Mu-template requires one template-file per snippet.
Put your text in a file (e.g.,html).
Then put the following in your .vimrc.
command Inshtml r html
I use Inshtml instead of inshtml because vim doesn't support user defined command starting with small letter.
Then if can type Inshtml in command mode (i.e., :Inshtml).