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 add default values to soy forms in a Stash add-on?

Alexandre Andrade May 21, 2013

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
Charles O'Farrell May 22, 2013

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

Karl Ostmo Sep 14, 2013

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

Charles O'Farrell Sep 14, 2013

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

Karl Ostmo Sep 14, 2013

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.

Charles O'Farrell Sep 14, 2013

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

Karl Ostmo Sep 17, 2013

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

Karl Ostmo Sep 22, 2013

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

Charles O'Farrell Sep 28, 2013

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

Olalekan Omotayo Aug 17, 2014

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.

0 votes
Karl Ostmo Sep 14, 2013

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

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in United States

Topic Tuesday: Agile

Another week, another Topic Tuesday!  Agile has been on my mind a lot lately because I've seen good implementations and bad implementations, but now as a Jira admin it matters more to me whether...

40 views 0 0
View post

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