# Show dialog with button in metadata banner

**URL:** <https://community.developer.atlassian.com/t/show-dialog-with-button-in-metadata-banner/21405>\
**Category:** Confluence Server\
**Tags:** javascript, soy, aui, confluence-server\
**Created:** [July 23, 2018, 2:14pm UTC](https://community.developer.atlassian.com/t/show-dialog-with-button-in-metadata-banner/21405 "2018-07-23T14:14:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcel.hoell](https://avatars.discourse-cdn.com/v4/letter/m/2acd7d/32.png) [@marcel.hoell](https://community.developer.atlassian.com/u/marcel.hoell)\
**Post date:** [July 23, 2018, 2:14pm UTC](https://community.developer.atlassian.com/t/show-dialog-with-button-in-metadata-banner/21405/1 "2018-07-23T14:14:27Z")

</div>

Hello,  
I want to write an add-on, which provides a button in the page.metadata.banner and opens up a dialog to fill in information. After submitting this information, I want to persist the data in the database.

Currently I got the following template (SOY):

```auto
<section id="page-status-dialog" class="aui-dialog2 aui-dialog2-large" role="dialog">
    <header class="aui-dialog2-header">

        <h2 class="aui-dialog2-header-main">Seitenstatus setzen</h2>

        <a class="aui-dialog2-header-close">
            <span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Schließen</span>
        </a>
    </header>
    
   <div class="aui-dialog2-content">
		<aui-label for="sync-product-single-select">Bitte Seitenstatus wählen:</aui-label>
	    <p>
	        <aui-select
	            id="sync-product-single-select"
	            name="product"
	            placeholder="Seitenstatus wählen">
	            <aui-option>Falscher Inhalt</aui-option>
	            <aui-option>Veralteter Inhalt</aui-option>
	            <aui-option>Unvollständiger Inhalt</aui-option>
	            <aui-option>Falscher Ablageort</aui-option>
	        </aui-select>
	    </p>
    </div>

    <footer class="aui-dialog2-footer">
        <div class="aui-dialog2-footer-actions">
            <button id="dialog-submit-button" class="aui-button aui-button-primary">OK</button>
            <button class="aui-button aui-button-link">Schließen</button>
        </div>

        <div class="aui-dialog2-footer-hint">Nach OK wird eine Mail mit dem Seitenstatus an betroffene Personen versandt.</div>
    </footer>
</section>

```

The following JS code was implemented so far.

```auto
AJS.toInit(function(){
    AJS.$('#page-status').click(function(e){
        e.preventDefault();
        AJS.dialog2("#page-status-dialog").show();
    });
});

```

And there is my problem: If I click onto the button “page-status”, which is defined as follows:

```auto
    <web-item key="page-status" name="Page Status" section="page.metadata.banner" weight="80">
            <link>/download/resources/${project.groupId}.${project.artifactId}:page-status-resources/images/pluginIcon.png</link>
        </icon>-->
        <label key="page.status.label"/>
        <tooltip key="page.status.label"/>
        <link linkId="page-status" absolute="true"/>
        <styleClass>aui-button aui-button-subtle</styleClass>
    </web-item>

```

I get the following error message in the console:

```auto
Uncaught TypeError: Cannot read property 'hasAttribute' of undefined

```

Why do I get this error message? And how can I send the information provided INSIDE the dialog to the REST interface, which I already created?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![christoffer](https://sea1.discourse-cdn.com/atlassiandeveloper/user_avatar/community.developer.atlassian.com/christoffer/32/33633_2.png) [@christoffer](https://community.developer.atlassian.com/u/christoffer)\
**Post date:** [July 24, 2018, 9:39am UTC](https://community.developer.atlassian.com/t/show-dialog-with-button-in-metadata-banner/21405/2 "2018-07-24T09:39:01Z")

</div>

You need to expose the soy template to the page in the atlassian-plugin.xml

```auto
 <web-resource key="" name="" >
...
        <dependency >confluence.web.resources:ajs</dependency >
...
        <context >page</context >
...
        <resource type="download" name="dialog.js" location="<path>/dialog.soy" />
        <transformation extension="soy" >
            <transformer key="soyTransformer" />
        </transformation >
...
    </web-resource >

```

And then on the page you have to actually insert the template into the DOM.

```auto
AJS.$("selector").html(TemplateNamespace.templateName())

```

Only after that could your selector in ‘AJS.dialog2(“#page-status-dialog”).show();’ actually find something.

You can then send the data to the server using AJS.$.ajax

```auto
$.ajax({
                'type': 'POST',
                'url': url, ...

```

[https://developer.atlassian.com/server/confluence/writing-soy-templates-in-your-plugin/](https://developer.atlassian.com/server/confluence/writing-soy-templates-in-your-plugin/)
