Find Questions…

Close ×
First time here? Check out the FAQ!

use of jquery in .vm

Shamith K S asked this question · 31 karma ·

Can we use jQuery in .vm ?

if yes, how ??

601 views

3 Answers:

Jamie Echlin · 48,692 karma ·

Did you put it in the "on document ready" function as Igor showed?

Shamith K S · 31 karma ·

"on document ready" function ???

Jamie Echlin · 48,692 karma ·

ie a block like this:

(function(){
...
})();

Meaning, run the code in the block when the page is fully parsed and the DOM is available.

Alexy Volkov · 31 karma ·

I will try to explain in a more detailed way.

You need to add this code in your script:

AJS.toInit(function (){

AJS.$("#description").text("JIRA") //or AJS.$("#description").val("JIRA") - if it input field

});

if this not help, then you can provide more info about a vm file, and we will try to help you

·1 user liked this

Shamith K S · 31 karma ·

Still no effect. I am editing description-edit.vm to add default value. its multi line value , i didnt find multiline character in vm syntax. so using java script. but not able to put value into the description text field..

Alexy Volkov · 31 karma ·

You can try to add HTML of your multilined value such as:

Atlassian<br>JIRA

Jamie Echlin · 48,692 karma ·

In vm syntax there is no syntax for it, you just do it like

<textarea>
a 
multiline
default
value
</textarea>
·1 user liked this

Shamith K S · 31 karma ·

Hi Jamie,

text area seems to be working. but i already hv a txt area. i want to add txt to it. i dont want to create a new txt area..

Shamith K S · 31 karma ·

Thanks a lot Alexy. AJSInit() worked. i had done mistake so it was not working. now it worked gud. solved my prob. thanks again.

thnks for Jamie too, i didnt knw abt this multinline in text area..

Igor Sereda · 4,292 karma ·

I wouldn't say it's "bad" as Alexy suggest, only a bit inconvenient - you can run into conflict between jQuery's $ and Velocity's $" In order to avoid problems, you need to assign $ to another variable:

<script>

(function(){

var q = AJS.$;

q('someselector');

})();

</script>

Of course if you have a large script, it's better extracted into a separate .js file and included on in the .vm via webResourceManager.

Shamith K S · 31 karma ·

Thanks Alexy and Igor for your responses. I want to assign default value to description text field using javascript in vm file.

i tried jQuery("#description").text("Jira");

jQuery("#$description").text("Jira");

tried AJS.$("#description").text("Jira");

but not getting value in text field. Am i missing anythin ?

Igor Sereda · 4,292 karma ·

If #description is an input or textarea, you need to use val(), not text().

Shamith K S · 31 karma ·

i tried that also. no change

Jamie Echlin · 48,692 karma ·

Did you put it in the "on document ready" function as Igor showed?

Alexy Volkov · 31 karma ·

Using Jquery in vm file is bad. But you can use it like that:

<script type="text/javascript">

id = AJS.$("someselector").attr("id")

</script>

Looking for something else?

Find Questions…

or Browse other questions tagged:

or Ask a Question