Developing custom field plugin

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2012

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
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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?

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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.

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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?

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

Yes, i do.

#if($maName!="ThisIsSystemMaNameWhichShowsThatThisFieldDoNotExistsInThatProject")
#customControlHeader ($action $customField.id $maName $fieldLayoutItem.required $displayParameters $auiparams)

<select class="select" name="$customField.id" id="$customField.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>
        
    #end
</select>

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

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

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

Unfortunatly it was useless(((

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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);

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

after inputing other value

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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


Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 14, 2012

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))

Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 14, 2012

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

0 votes
Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

Nic, i explained below. And added some code

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 13, 2012

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)

0 votes
Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

Simple text customfield. I'm trying to set it's behaviour in plugin. Now o need to set it as required. in class MyCF.java 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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 13, 2012

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?

0 votes
Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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
Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

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

0 votes
Andrew Pechnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2012

Nic, looks like this plugin adds validation in a workflow

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2012

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.

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2012

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

Suggest an answer

Log in or Sign up to answer