Create dialog, set content and return value from component

I create in vm button

<input type="button" value="Change status" onClick="run()"/>

in js file i have

function run() {
        AJS.$(document).ready(function () {
            var popup = new AJS.Dialog(470, 250);
            popup.addHeader("Header");
            popup.addButton("Ok", function (dialog) {
//get content
            });
            popup.addCancel("Cancel", function (dialog) {
                dialog.hide();
            }, "#");
            popup.addPanel("SinglePanel", getContentComment(), "singlePanel");

            popup.show();
        });
}
function getContentComment() {
    var str = "";
    str += "<textarea class='textarea' name='tag_name' id='tag_id' rows='8'></textarea>";
    return str;
}

and i want get text from text area.

it's doing in get content, i think, but how?

1 answer

This widget could not be displayed.

There are many opportunities to do that.

First, you have the "id" attribute in your input - just use it: AJS.$('#tag_id').val()!!

Second, you can add in AJS.Dialog constructor "id" property(look here), so when you need to get text from it's element it will be like this:

AJS.$('#example-dialog [name=tag_name]').val()

Next, to get dialog element you can use "popup.element" property

var dialog = new AJS.Dialog(100,100);
var text = AJS.$(dialog.popup.element).find('[name=tag_name]').val()

Also, you can pass in "addPanel" not only html code, but the selector of element to paste. so you can create somewhere

(your page html)
<div id="test"><textarea class='textarea' name='tag_name' rows='8'>/textarea></div>
...
(js)
popup.addPanel('SinglePanel', '#test', 'singlePanel');

and when you write AJS.$('#test [name=tag_name]').val() it works

Good luck!

Thanks! I have been trying to figure out why AJS.$('#comment').val() returns "" and after much fiddling in developer tools I almost gave up. This worked AJS.$('#comment-edit [name=comment]').val()

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

155 views 2 0
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you