Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to use JavaScript in Velocity file from Webwork1 module?

I have an Atlassian SDK webwork1 module with its view:

<webwork1 key="ai-config" name="AI Config" i18n-name-key="ai-config.name"> 
<description key="ai-config.description">The AI Config Plugin</description>
<actions>
<action name="com.softgile.jira.webwork.AIConfigAction" alias="AIConfigAction">
<view name="success">/templates/ai-config/success.vm</view>
</action>
</actions>
</webwork1>

In the view I have several forms:


<form class="aui" id="configForm" method="post" action="AIConfigAction!saveIp.jspa">

...

</form>

<form class="aui" id="serviceName" method="post" action="AIConfigAction!saveService.jspa">

...

</form>

Also I have a button there, which is controlled with JS:


<div class="field-group">
<label for="authenticate">
<span class="aui-icon aui-icon-large aui-iconfont-app-access">Insert meaningful text here for accessibility</span>
</label>
<div class="buttons">
<button class="aui-button aui-button-primary" id="authenticate">Authenticate</button>
</div>
</div>

In JS file I have something like this:


AJS.toInit(function(){

AJS.$(document).on('click', '#authenticate', function(e) {
e.preventDefault();
alert("authenticate");
});


});

Both forms work okay, and JS works when I click the button. But JS stops working when I submit one of the forms, it works only before submitting forms. I see that URL is changing from AIConfigAction.jspa to AIConfigAction!saveService.jspa and in that case JS not working. How can I make JS work?

 

1 answer

1 accepted

0 votes
Answer accepted

I have found the solution myself. So, the problem in my case was that I was including web-resources  inside doExecute() method of the Webwork. That is why after calling other methods like doSave() web-resources stopped working. 

Solution - move web-resources inclusion to Webwork constructor:

@Inject
public AIConfigAction(WebResourceManager webResourceManager) {

webResourceManager.requireResourcesForContext("myPlugin");

}

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

3,742 views 5 15
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you