How to add default values to soy forms in a Stash add-on?

I'm creating a hook for Stash, it has a form editor to set an URL. I want to know if it's possible to give a textField a default value, so that it doesn't have to be configured everytime.

These are the contents of the soy file:

{namespace stash.config.example.hook.simple}

{template .formContents}
    {call aui.form.textField}
        {param id: 'url' /}
        {param value: $config['url'] /}
        {param labelContent}
            {stash_i18n('stash.web.test.hook.config.label', 'URL')}
        {/param}
        {param descriptionText: stash_i18n('stash.web.test.hook.config.description', 'URL to be notified.') /}
        {param extraClasses: 'long' /}
        {param errorTexts: $errors ? $errors['url'] : null /}
    {/call}
{/template}

2 answers

1 accepted

1 vote
Answer accepted

Hi Alexandre,

{param value: $config['url'] ? $config['url'] : 'Default value'  /}

You could set the value of the textField if 'url' hasn't already been set.

Cheers,

Charles

What technique should we use to make checkboxes checked by default?

Hi Karl,

{call aui.form.checkboxField}
    {param fields: [
        ['id': 'test', 'labelText': 'Hello world', 'isChecked': true]
     ]/}
{/call}

While I know this isn't ideal, I recommend having a look at the form.soy from AUI for the full list of parameters:

https://bitbucket.org/atlassian/aui/src/master/auiplugin/src/main/resources/soy/atlassian/form.soy

You might find some of the comments/examples/links on this Answer useful too:

https://answers.atlassian.com/questions/194459/how-do-i-use-soy-with-stash-to-make-useful-configuration-pages

Cheers,

Charles

Charles,

That make the checkbox always checked, even if the user un-checks it and saves. When the configuration dialog is opened again, the box is re-checked.

Karl,

Sorry, I wasn't thinking.

{call aui.form.checkboxField}
    {param fields: [
        ['id': 'test', 'labelText': 'Hello world', 'isChecked': $config['test']]
     ]/}
{/call}

Or something along those lines. Does that work?

Charels

That allows the user to set the value, but it doesn't make the checkbox checked by default.

I guess that I could work around this by inverting the semantics of my checkbox, such that the sensible default is unchecked.

Hi Karl,

Apologies again. So what about this (actually tested)?

{call aui.form.checkboxField}
    {param fields: [
        ['id': 'test', 'labelText': 'Hello world', 'isChecked': $config['test'] != null ? $config['test'] : true]
     ]/}
{/call}

Charles

Hi Karl,

I have this in my simple.soy file for a stash hook:

{namespace com.atlassian.tutorial.helloworld}
/**
 * @param config
 * @param? errors
 */
{template .formContents}
	{call aui.form.checkboxField}
        {param fields: [
        ['id': 'test', 'labelText': 'Hello world', 'isChecked': $config['test'] != null ? $config['test'] : true] 
        ]/}
    {/call}
{/template}

However when I try to test the hook, I get the following error:

Failed to load config form: com.atlassian.tutorial.helloworld:hello-world-pre-receive-repository-hook-config-form, errors: TypeError: Cannot read property 'length' of undefined

Any ideas why I am getting this error?

Lekan.

What technique should we use to make checkboxes checked by default?

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 14 hours ago in United States

Atlassian acquires AgileCraft

         Good Day, Bad bad traffic, not sure why!!!! 1/2 hour commute took me 2 hours today 🤯 What helped me is that I kept browsing LinkedIn until...

47 views 4 0
View post

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