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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I change $maName to $customField.name but changes still don't apply
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Put the header and footer outside of if loop and see if it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunatly it was useless(((
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If it may help until i insert validation, everything worked fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure what is going wrong. There must be some error! Why are you getting the field in the method?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I' sorry, Jobin, but i don't understand your question...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
after inputing other value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no progress((( no any error messages(( this screenshot shows that validation works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am afraid I don't have anything new to try!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now everything is okey. Thank you very much, gentlemens!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nic, i explained below. And added some code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jobin, Nic, much thanks for your response
Jobin, only while editing and creaeting the issue.
Nic, thank you, i will try.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Nic, looks like this plugin adds validation in a workflow
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where do you need the field as required? In a workflow? or in one purticular step while ediing the issue? While creating?
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.