Modify

Opened 10 years ago

Closed 8 years ago

#12005 closed defect (fixed)

Validating a value is present for MultiSelect

Reported by: anonymous Owned by: Ryan J Ollos
Priority: normal Component: DynamicFieldsPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.0

Description (last modified by Ryan J Ollos)

What's the best implementation for validating for value <> '' for unhidden custom fields. I am using DynamicFieldsPlugin with MultiSelectFieldPlugin. Here is a sample of my trac.ini:

ci_appls = text
ci_appls.clear_on_hide = true
ci_appls.format = list
ci_appls.hide_when_component = Facility
ci_appls.invalid_if =
ci_appls.label = Application CIs Affected
ci_appls.multiselect = true
ci_appls.options = Desk Top|Help Desk Application
ci_appls.order = 8
ci_appls.value =
ci_appls.show_when_component = Applications
ci_facility = text
ci_facility.clear_on_hide = true
ci_facility.format = list
ci_facility.hide_when_component = Applications
ci_facility.invalid_if =
ci_facility.label = Facility CIs Affected
ci_appls.multiselect = true
ci_appls.options = Power|Cooling
ci_appls.order = 9
ci_appls.value =
ci_appls.show_when_component = Facility

The invalid_if does not catch the error.

Attachments (0)

Change History (12)

comment:1 Changed 10 years ago by Olli Kallioinen

Sorry, I haven't used DynamicFieldPlugin so I don't know.

comment:2 Changed 10 years ago by anonymous

Regardless of the DynamicFieldPlugin, if I want to ensure something is selected from the multi select field when it is not hidden how would I do it?

comment:3 Changed 10 years ago by anonymous

I believe the fact that it is a list is throwing off the "invalid_if" check from the DynamicFieldsPlugin.

comment:4 Changed 10 years ago by Ryan J Ollos

Description: modified (diff)

comment:5 Changed 9 years ago by Ryan J Ollos

Cc: Ryan J Ollos added

comment:6 Changed 8 years ago by Olli Kallioinen

I had some spare time and installed DynamicFieldsPlugin to see what the problem is. It seems that dynamic fields thinks that the field is hidden and does not check it's validity (dynamicfieldsplugin/trunk/dynfields/htdocs/rules.js#L277).

is(":hidden") returns true because multiselection works by using a normal text field, hiding it and syncing the data to an additional form field that actually shows the options list.

The problem is that is(":hidden") checks if the text field is actually visible so changing size to 0 etc. will not work either. Some kind of workaround is probably possible, but it might be easier to fix this in DynamicFieldsPlugin. rjollos what do you think?

Last edited 8 years ago by Ryan J Ollos (previous) (diff)

comment:7 Changed 8 years ago by Ryan J Ollos

comment:description has contradictory rules:

ci_appls.hide_when_component = Facility
ci_appls.show_when_component = Applications
ci_appls.show_when_component = Facility

DynamicFieldsPlugin has no knowledge of MultiSelectFieldPlugin, but we could change that with a patch like the following:

  • dynamicfieldsplugin/trunk/dynfields/htdocs/rules.js

     
    271271
    272272    // proceed only if input field matches the spec's target field
    273273    if (input.attr('id') == field.attr('id')){
     274        // Is it a multiselect field added by MultiSelectFieldPlugin (#12005)?
     275        var ismultiselect = field.next(".multiselect").length !== 0;
    274276
    275277        // listen for form submission
    276278        form.submit(function(){
    277             if (field.is(":hidden"))
     279            if (field.is(":hidden") && !ismultiselect)
    278280                return true;
    279281            if ((spec.value == "" && input.val() == "") ||
    280282                (spec.value != "" && new RegExp(spec.value).test(input.val()))){

I will think about whether there might be a better way before committing to the solution.

comment:8 Changed 8 years ago by Olli Kallioinen

Hmm. Maybe add an extra class specifier to fields that are hidden in DynamicFieldsPlugin and use that to determine if the field needs to be validated.

comment:9 in reply to:  8 Changed 8 years ago by Ryan J Ollos

Replying to ollika:

Hmm. Maybe add an extra class specifier to fields that are hidden in DynamicFieldsPlugin and use that to determine if the field needs to be validated.

How about the class validate-when-hidden? If that sounds good to you and you want to make the change to MultiSelectFieldPlugin, I'll change DynamicFieldsPlugin later this week and test them working together.

comment:10 Changed 8 years ago by Olli Kallioinen

What I was thinking was that DynamicFieldsPlugin could add a class specifier itself to signify fields that it's hiding. Then before the validation it could check if that class is defined for the field instead of checking if the fields are actually hidden.

I took a better look and it actually already adds "dynfields-hide" class to all fields that it hides.

so just changing: if (field.is(":hidden"))

to something like if (field.hasClass("dynfields-hide")) would probably do the trick.

Of course I'm not 100% sure if there are some other cases where it actually matters to check that the field is really hidden. With a quick search for hide() I think the only other case is that the field is defined to be always hidden and in that case the validation is probably not relevant anyway.

comment:11 Changed 8 years ago by Ryan J Ollos

Cc: Ryan J Ollos removed
Component: MultiSelectFieldPluginDynamicFieldsPlugin
Owner: changed from Olli Kallioinen to Ryan J Ollos
Status: newassigned

That will probably work. I'll take a closer look.

comment:12 Changed 8 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

In 15035:

2.2.0dev: Validate multiselect custom fields

Fixes #12005.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.