Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to use JavaScript in Velocity file from Webwork1 module?

Seyid Aghayev January 13, 2021

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
Seyid Aghayev January 14, 2021

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
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events