Developing custom field plugin

Hello, dear developers!

I'd like to set my custom field required and as i know there're 2 ways: make it required via Field Configuration Scheme or to make a Validation of this field. The first way is not possible. So the question is : Is it aviable to set validation in customfield which extend TextCFType class? Or are there any methods which can make field required for Project or for Issue?

Best wishes, Andrew

10 answers

1 accepted

3 votes
Accepted answer

If you want to handle validation during editing, validateFromParams is indeed the method.

but i dont now how to set conclusion on CF value

What do you mean by this?

OMG i ment condition of course))))

public void validateFromParams(CustomFieldParams relevantParams, ErrorCollection errorCollectionToAddTo, FieldConfig config)
    	CustomField customField=config.getCustomField();
    	String selectedString = (String)relevantParams.getFirstValueForNullKey();
        if(!(StringUtils.isNotBlank(selectedString) && !"-1".equals(selectedString)))

                errorCollectionToAddTo.addError(customField.getId(), "This custom field is required.");


Now it shows message when CF is empty
But strange! When CF is filled with some value pressing on "update" button nothing happens.
No error message and no updating CF values.

That should be something to do with your edit template. Do you have the required headers, with custom field id etc, in the edit template?

Yes, i do.

#customControlHeader ($action $ $maName $fieldLayoutItem.required $displayParameters $auiparams)

<select class="select" name="$" id="$">
        <option value="")>$i18n.getText("common.words.none")</option>
    #foreach ($cfValue in $cfValues)
            <option#if ($value && $value == $cfValue) selected="selected"#end value="$cfValue">$cfValueEncoder.encodeForHtml($cfValue)</option>

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

I changed customfield display name to maName. All other things i left as default. And yes, my customfild type extends TextCFType, just i needed some customization

I change $maName to $ but changes still don't apply

Put the header and footer outside of if loop and see if it helps.

Unfortunatly it was useless(((

If it may help until i insert validation, everything worked fine.

Not sure what is going wrong. There must be some error! Why are you getting the field in the method?

I' sorry, Jobin, but i don't understand your question...

Never mind. You need it for adding to the errorCollection.

Call this so that you know if you are missing any other validations.

super.validateFromParams(customFieldParams, errorCollection, fieldConfig);

after inputing other value

no progress((( no any error messages(( this screenshot shows that validation works

I am afraid I don't have anything new to try!

Jobin, firstfull my validation worked if only "None" option value is "-1".
On the other hand, it began to work whe in if clause was ("-1".StringUtols.equalsTo(selectedString))

Now everything is okey. Thank you very much, gentlemens!

0 votes

Where do you need the field as required? In a workflow? or in one purticular step while ediing the issue? While creating?

0 votes

The "field is mandatory" validators you can find in several plugins (e.g. Jira Suite Utilities) will validate any custom field, you won't need to worry about it.

Nic, looks like this plugin adds validation in a workflow

Jobin, Nic, much thanks for your response
Jobin, only while editing and creaeting the issue.
Nic, thank you, i will try.

So, i tried ti validate it. validateFromParams method works but i dont now how to set conclusion on CF value. PLease help me if you can)

0 votes

I'm not sure what you are doing, could you explain where you're using that call and give us a brief outline of what you have set up, and what you are trying to do?

Simple text customfield. I'm trying to set it's behaviour in plugin. Now o need to set it as required. in class i override method validateFromParams. to set validation which will stop user when he will try to apply issue editing when this CF is empty.

0 votes

Ah, I missed your previous comment about validating in workflow, rather than field.

Which validateFromParams method are you using? I mean, which class is it coming from or what have you imported to provide it in your code?

(also what does "set conclusion on CF value" mean? Validation should be a simple "valid" or "not valid, here's an error" type process)

Nic, i explained below. And added some code

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,095 views 4 9
Read article

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