1
0
-1

Can we use jQuery in .vm ?

if yes, how ??

    CommentAdd your comment...

    3 answers

    1.  
      1
      0
      -1

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

      1. Shamith K S

        "on document ready" function ???

      2. Alexy Volkov

        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

      3. Jamie Echlin

        ie a block like this:

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

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

      4. Shamith K S

        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..

      5. Alexy Volkov

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

        Atlassian<br>JIRA

      6. Jamie Echlin

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

        <textarea>
        a 
        multiline
        default
        value
        </textarea>
      7. Shamith K S

        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..

      8. Shamith K S

        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..

      CommentAdd your comment...
    2.  
      2
      1
      0

      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.

      1. Shamith K S

        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 ?

      2. Igor Sereda

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

      3. Shamith K S

        i tried that also. no change

      4. Jamie Echlin

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

      CommentAdd your comment...
    3.  
      1
      0
      -1

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

      <script type="text/javascript">

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

      </script>

        CommentAdd your comment...