Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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 can I create a custom field, that reveals a 2nd field if the 1st field is a certain value? Edited

Hello!

 

So what i'm currently working on is creating a dropdown search field that allows you to pick from a list of companies, then if the company you want it not listed, you can select 'new company' and then a text box will appear where you can fill in the new company. 

 

So far i've for a simple dropdown menu, and I'm trying to figure out how can i implement that new 2nd field to accompany the first. 

Here's my dropdown field as it is now:

```java

@Scanned
public class ClientField extends SelectCFType {


private final OptionsManager optionsManager;

protected ClientField(@JiraImport CustomFieldValuePersister customFieldValuePersister,
@JiraImport OptionsManager optionsManager,
@JiraImport GenericConfigManager genericConfigManager,
@JiraImport JiraBaseUrls jiraBaseUrls) {

super(customFieldValuePersister, optionsManager, genericConfigManager, jiraBaseUrls);
this.optionsManager = optionsManager;
}

@Override
public Map<String, Object> getVelocityParameters(final Issue issue,
final CustomField field,
final FieldLayoutItem fieldLayoutItem) {

final Map<String, Object> parameters = super.getVelocityParameters(issue, field, fieldLayoutItem);//
FieldConfig fieldConfiguration = null;
if(issue == null)
{
fieldConfiguration = field.getReleventConfig(new SearchContextImpl());
} else
{
fieldConfiguration = field.getRelevantConfig(issue);
}
Options options = this.optionsManager.getOptions(fieldConfiguration);
this.optionsManager.createOption(fieldConfiguration, null, new Long(1), "New Client");
// TODO: Populate other options with 'Company names' from DB
return parameters;
}
}

```

Here is my edit.vm file so far. Basically just populating the dropdown with the options.

Also it checks if the dropdown equals 'New Client' and includes an additional `<input>` tag. This part does not work 

 

edit.vm:

```vm

#customControlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters $auiparams)

<select class="select" name="$customField.id" id="$customField.id">
#if (!$fieldLayoutItem || $fieldLayoutItem.required == false)
<option value="-1">$i18n.getText("common.words.none")</option>
#else
<option value="">$i18n.getText("common.words.none")</option>
#end
#foreach ($option in $configs.options)
#if(!$option.disabled || $option.disabled == false || ($value && $value == $option.optionId.toString()))
<option#if ($value && $value == $option.optionId.toString()) selected="selected"#end value="$option.optionId">$cfValueEncoder.encodeForHtml($option.value)</option>
#end
#end
</select>

#if ($value.equals("New Client"))
<input type="text"
name="$customField.id"
value="$!value" />
#end

#customControlFooter ($action $customField.id $fieldLayoutItem.fieldDescription $displayParameters $auiparams)

```

For readaibility, i put these snippets in pastebin as well:

edit.vm

ClientField.java

 

Side question, is there a different field besides `SelectCFType` that lets the user search all the options? 

 

Any suggestions with how to approach this problem would be really appreciated. Thanks for your help!

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

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