Validation or default values for repeatableHeteroProperty

79 views
Skip to first unread message

Stefan Wolf

unread,
Feb 17, 2015, 6:02:46 AM2/17/15
to jenkin...@googlegroups.com
Hi,

I am using a repeatableHeteroProperty to configure a list of reports to generate. Now I want to validate in the UI that this list is not empty.
Is this possible?
An alternative would be to start with a default entry in the list when the publisher is newly added. How can I achieve this?
Currently I am adding the default element in the DataBoundConstructor. This is somewhat unexpected, since the UI does not show this entry on saving.
Any help is welcome...

Regards,
Stefan

Jesse Glick

unread,
Feb 18, 2015, 3:54:12 PM2/18/15
to Jenkins Dev
On Tue, Feb 17, 2015 at 6:02 AM, Stefan Wolf <glow...@gmail.com> wrote:
> I am using a repeatableHeteroProperty to configure a list of reports to
> generate. Now I want to validate in the UI that this list is not empty.
> Is this possible?

Not sure. You would expect to be able to add to the descriptor

public FormValidation doCheckReports(@QueryParameter List<Report> value) {
return value.isEmpty () ? FormValidation.error("empty!") :
FormValidation.ok();
}

If that works, I would suggest filing a PR for the ui-samples-plugin
to demonstrate it. If not, something needs to be implemented in
repeatableHeteroProperty.jelly.

Stefan Wolf

unread,
Feb 20, 2015, 3:52:00 AM2/20/15
to jenkin...@googlegroups.com
Hi,

Am Mittwoch, 18. Februar 2015 21:54:12 UTC+1 schrieb Jesse Glick:
On Tue, Feb 17, 2015 at 6:02 AM, Stefan Wolf <glow...@gmail.com> wrote:
> I am using a repeatableHeteroProperty to configure a list of reports to
> generate. Now I want to validate in the UI that this list is not empty.
> Is this possible?

Not sure. You would expect to be able to add to the descriptor

public FormValidation doCheckReports(@QueryParameter List<Report> value) {
    return value.isEmpty () ? FormValidation.error("empty!") :
FormValidation.ok();
}

Thats what I tried and it didn't work.
 
If that works, I would suggest filing a PR for the ui-samples-plugin
to demonstrate it. If not, something needs to be implemented in
repeatableHeteroProperty.jelly.

So seems like I need to implement something.
Any ideas how to add default values for a field like that?

Regards,
Stefan 

Jesse Glick

unread,
Feb 20, 2015, 3:48:04 PM2/20/15
to Jenkins Dev
On Fri, Feb 20, 2015 at 3:51 AM, Stefan Wolf <glow...@gmail.com> wrote:
> So seems like I need to implement something.

Seems so.

> Any ideas how to add default values for a field like that?

I would suggest focusing your time on adding validation, which is more
broadly useful than default values. (Default values also tend to
interact poorly with other features.)

You would have to dig around to see where and how this is implemented
for existing controls. Search for checkUrl attribute in taglibs, CSS
class ‘validated’, and hudson-behavior.js sections for
registerValidator and FormChecker and controlValue.

Stefan Wolf

unread,
Feb 23, 2015, 3:51:12 AM2/23/15
to jenkin...@googlegroups.com
After reading a bit of code it seems to me that the current validation only support "primitive" fields - Strings, Booleans, ...
So this would be a bigger change. Do you have any idea where one should start or how this should be done?

Regards,
Stefan

Jesse Glick

unread,
Feb 23, 2015, 7:22:24 PM2/23/15
to Jenkins Dev
On Mon, Feb 23, 2015 at 3:51 AM, Stefan Wolf <glow...@gmail.com> wrote:
> After reading a bit of code it seems to me that the current validation only
> support "primitive" fields - Strings, Booleans, ...

Yeah, you would need to package up other objects as JSON I suppose.
Reply all
Reply to author
Forward
0 new messages