Opened 10 years ago
Closed 9 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 )
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
comment:2 Changed 10 years ago by
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
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
Description: | modified (diff) |
---|
comment:5 Changed 10 years ago by
Cc: | Ryan J Ollos added |
---|
comment:6 Changed 9 years ago by
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?
comment:7 Changed 9 years ago by
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
271 271 272 272 // proceed only if input field matches the spec's target field 273 273 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; 274 276 275 277 // listen for form submission 276 278 form.submit(function(){ 277 if (field.is(":hidden") )279 if (field.is(":hidden") && !ismultiselect) 278 280 return true; 279 281 if ((spec.value == "" && input.val() == "") || 280 282 (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 follow-up: 9 Changed 9 years ago by
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 Changed 9 years ago by
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 9 years ago by
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 9 years ago by
Cc: | Ryan J Ollos removed |
---|---|
Component: | MultiSelectFieldPlugin → DynamicFieldsPlugin |
Owner: | changed from Olli Kallioinen to Ryan J Ollos |
Status: | new → assigned |
That will probably work. I'll take a closer look.
Sorry, I haven't used DynamicFieldPlugin so I don't know.