Hi all,
I've seen plenty of questions asked of the multi-select autocomplete field, but I'm not sure if something similar is available for the single text field. Basically, I just want the ability to have a type-ahead option on my custom field so I'm not typing "Ford Car" when I actually called the same value "Ford" on another issue.
I'm looking for something similar, if not identical, to what's available for Version and Epic fields already.
Currently we're using the OnDemand hosted solution but we'll soon be switching to an internal, Download instance. Any ideas out there?
Cheers,
Dave
Hi David,
We are using JIRA 6.1.4 downloaded instance and in this version an autocomplete field is not available either. Maybe this thread will help you out:
https://answers.atlassian.com/questions/84612/how-to-add-auto-complete-rendere-to-any-custom-field
Our JIRA is currently hosted in the Amazon cloud. More info can be found here:
It is a very good and reliable hosting solution that enables you to configure a hosting plan specifically for your needs.
Thanks Benji... But am I correct in saying that answer is for multiple select lists? I am trying to add it to a standard text field entry, not a multi select list...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
The idea is indeed to start from a multiselect list, but the javascript converts this custom field to some kind of autocomplete combobox that allows typing:
To get this behavior, you have to do the following:
1) Create a custom field that uses a multiselect list (I know it sounds weird, but this is just a way to provide all the values you need for the autocomplete)
2) Paste the following code in the description field of your custom field (credits to CK1 for providing the code):
<script type="text/javascript"> (function($) { // "customfield_10400" is the number of the custom // multiselect field you want to change as e.g. // seen at the end of the "configure" page url of // the field you want to change this way AJS.$("#customfield_10400 option[value='-1']").remove(); //Removes the default value "None" function convertMulti(id){ if (AJS.$('#'+id+"-textarea").length == 0){ new AJS.MultiSelect({ element: $("#"+id), itemAttrDisplayed: "label", errorMessage: AJS.params.multiselectComponentsError }); } } AJS.toInit(function(){ convertMulti("customfield_10400"); }) JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) { AJS.$("#customfield_10400 option[value='-1']").remove(); convertMulti("customfield_10400"); }); })(AJS.$); </script>
3) Lookup the id of your custom multiselect field (in this example 10400) and replace all the id's in the javascript code by your own id's.
4) Add the field to a screen and make sure the screen is visible somewhere.
This is all you need to do to implement this kind of autocomplete text field.
Hope this solution works for you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have tested it on a download instance, but it is just javascript that you add to description field. In that way it is version independent.
Glad I could help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wow. Massive thanks for that explanation! Does this work on both download and on-demand instances?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
I did some additional testing and indeed you can not place javacript code in an ondemand version :/ It is not interpreted as javascript, but simply as regular text. This thread deals with the same issue:
https://answers.atlassian.com/questions/185010/upload-add-on
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, so I noticed. Luckily as mentioned before we'll be rolling to an internal download version soon so hopefully I can still use this!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Then Amazon hosting is still a good option ;-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I was able to implement this, which is nice - but I'm confused. Do I still have to create options in the background that populate this list? I was under the impression that something not presently in the list would be added automatically? Currently I get the message "Invalid value 'xxx' passed for customfield 'yyy'"
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.
Hello! This script searches text only from start, is it possible to change script so, that it seraches by "contains"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted]
is there a way to adapt your solution to a single select field?
Thanks,
Richard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
See this support page, which describes how to do what you're asking. It says it's for a multi-select field, but I've read reports of people successfully applying this to single select field as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Richard Bergmann
I replace AJS.MultiSelect in @Benji Mommen [ACA IT] 's solution with AJS.SingleSelect, and it works for me.
<script type="text/javascript">
(function($) {
// "customfield_10000" is the number of the custom
// multiselect field you want to change as e.g.
// seen at the end of the "configure" page url of
// the field you want to change this way
function convertSingle(id){
if (AJS.$('#'+id+"-textarea").length == 0){
new AJS.SingleSelect({
element: $("#"+id),
itemAttrDisplayed: "label",
errorMessage: AJS.params.multiselectComponentsError
});
}
}
AJS.toInit(function(){
convertSingle("customfield_10000");
})
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
AJS.$("#customfield_10000 option[value='-1']").remove();
convertSingle("customfield_10000");
});
})(AJS.$);
</script>
for your reference :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Benji Mommen [ACA IT], any ideas why inline editing is not working for such custom field adjusted to autocomplete with a script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, David,
If you are talking about a custom field for JIRA issue, the simpliest way to add the autocomplete option is to create a custom field plugin. It will take you just about 30 minutes if you know how to deal with JIRA SDK.
Add custom field module
<customfield-type key="car-key" name = "Car" class="com.about.jira.customfields.car"> <description>Car field</description> <resource type="velocity" name="view" location="vm/view-car.vm"/> <resource type="velocity" name="column-view" location="vm/view-car.vm"/> <resource type="velocity" name="edit" location="vm/edit-car.vm"/> <resource type="velocity" name="xml" location="vm/xml-car.vm"/> <valid-searcher package="com.atlassian.jira.plugin.system.customfieldtypes" key="textsearcher"/> </customfield-type>
Implement the custom field class
public class Car extends GenericTextCFType { private final Car[] allCars; // Car type should have id and name public fields protected Car(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager) { super(customFieldValuePersister, genericConfigManager); this.allCars = ...; // get the list of cars, e.g. from DB } @Override public Map<String, Object> getVelocityParameters(Issue issue, CustomField field, FieldLayoutItem fieldLayoutItem) { Map<String, Object> params = super.getVelocityParameters(issue, field, fieldLayoutItem); params.put("cars", allCars); params.put("default_value", getDefaultValue(field)); params.put("value", issue != null ? field.getValue(issue) : null); return params; } }
Implement velocity templates. Here a piece of edit-car.vm, which I copypasted from JIRA select field
#disable_html_escaping() #customControlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters $auiparams) <select class="select cf-select" name="$customField.id" id="$customField.id"> #if (!$fieldLayoutItem || $fieldLayoutItem.required == false) <option value="-1">$i18n.getText("common.words.none")</option> #else #if ( !$configs.default ) <option value="">$i18n.getText("common.words.none")</option> #end #end #foreach ($option in $cars) <option#if ($value && $value == $option.id) selected="selected"#end value="$option.id">$cfValueEncoder.encodeForHtml($option.name)</option> #end #end </select> #customControlFooter ($action $customField.id $fieldLayoutItem.fieldDescription $displayParameters $auiparams)
The thing worth mentioning is select class - JIRA replaces it with auiSelect2 class at runtime.
The other templates (view-car.vm and so on) are very simple:
#disable_html_escaping() #if ($value) $cfValueEncoder.encodeForHtml($!value.toString()) #end
Again, just copypaste from JIRA template view-select.vm (WEB-INF/classes/templates/plugins)
Anyway, JIRA templates are a very good source of information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you do do the multi-select field jiggery-pokery and get it working as an autocomplete text field, is it possible to tell it to pick up the options from various sources? For example, in the Summary field, it would be great if it could search Confluence article titles and also other Jira issue Summary fields and try to match/autocomplete against that.
This seems sensible in an effort to keep to common language and not end up creating new "different" issues for stuff that's already in there somewhere, probably with a handy resolution or knowledge article.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.