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}
Community moderators have prevented the ability to post new answers.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
Cheers,
Charles
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That allows the user to set the value, but it doesn't make the checkbox checked by default.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess that I could work around this by inverting the semantics of my checkbox, such that the sensible default is unchecked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What technique should we use to make checkboxes checked by default?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Appreciate this is a late response but I've been stuck on this for a while too.
The problem is that checkboxes are not contained in $config when they are set to false (same as HTML forms) and soy will coerce missing values to false. I found this with the soy debugger[1].
My workaround for this is to detect when the $config map is empty and then use the default value, otherwise coerce the value from where the checkbox data _should_ be in the map. This works because soy expressions are truthy and don't error on missing/null values[2]:
Here's a complete example:
{call aui.form.checkboxField}
{param legendContent: 'Wait' /}
{param fields: [[
'id' : 'wait',
'labelText' : 'Wait for deployment to finish when pushing',
'isChecked': (length(keys($config)) == 0) ? true: $config['wait']
]] /}
{/call}
HTH
---
[1] https://github.com/google/closure-templates/blob/master/documentation/reference/debugger.md
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.