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

This widget could not be displayed.

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.

#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

I change $maName to $customField.name 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!

This widget could not be displayed.

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

This widget could not be displayed.

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.

This widget could not be displayed.

Nic, looks like this plugin adds validation in a workflow

This widget could not be displayed.

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

This widget could not be displayed.

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)

This widget could not be displayed.

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?

This widget could not be displayed.

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.

This widget could not be displayed.

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)

This widget could not be displayed.

Nic, i explained below. And added some code

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

137 views 2 0
Join discussion

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