#1834 closed defect (fixed)
Select field with empty options causes problem
Reported by: | Owned by: | osimons | |
---|---|---|---|
Priority: | high | Component: | CustomFieldAdminPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.11 |
Description
Hi there,
I am experiencing a problem with your plugin. I have a select field with some options, but also null as an option. The field works as desired in the ticket creation form. But if I use the CustomField console in the webadmin sectio to look at the field, the null option is ignored and it only lists the values in the textarea that actually have a value. I don't know if this is a Firefox bug, but I saw that it would be alright if an additional line break before the first 'real' option would be inserted.
Attachments (0)
Change History (9)
comment:1 Changed 17 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:2 Changed 16 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Trac Release: | 0.10 → 0.11 |
reopening because I experience the very same behaviour with version 0.2 from 02/2009 this is Safari on OS X 10.5.6
comment:3 Changed 16 years ago by
Really? Same OS/Safari on my end, and it works fine for me.
Could you try to install/upgrade directly from repos:
easy_install -U http://trac-hacks.org/svn/customfieldadminplugin/0.11
Please report back.
comment:4 follow-up: 5 Changed 15 years ago by
If a custom field of type "select" shall be optional, the first option shall be an empty line. This works, if you create the custom field, or edit it. But if you press the button "Apply changes" the empty option is removed. Tested with Firefox and IE on RHEL 3.5 and openSUSE 10.3 with TracCustomFieldAdmin 0.2
custom field settings in trac.ini after "Save, or Add"
fix_in_r06 = select fix_in_r06.format = plain fix_in_r06.label = Fix in R06 fix_in_r06.options = |Iteration6|trunk|branchxx|xxxxx fix_in_r06.order = 2 fix_in_r06.value =
custom field settings in trac.ini after "Apply Changes"
fix_in_r06 = select fix_in_r06.format = plain fix_in_r06.label = Fix in R06 fix_in_r06.options = Iteration6|trunk|branchxx|xxxxx fix_in_r06.order = 2 fix_in_r06.value =
The leading '|' is removed, and the custom field is not longer optional
comment:5 Changed 13 years ago by
Replying to martins:
But if you press the button "Apply changes" the empty option is removed.
I have the same issue. "Apply changes" button occurs it.
It will be fixed with the following patch;
#! Index: customfieldadmin/customfieldadmin.py =================================================================== --- customfieldadmin/customfieldadmin.py (revision 10367) +++ customfieldadmin/customfieldadmin.py (working copy) @@ -97,6 +97,8 @@ cf = cfapi.get_custom_fields() for cur_cf in cf: cur_cf['order'] = order[cur_cf['name']] + if cur_cf.get('optional', False): + cur_cf['options'] = [''] + cur_cf['options'] cfapi.update_custom_field(cur_cf) req.redirect(req.href.admin(cat, page))
comment:6 follow-up: 7 Changed 13 years ago by
This was a long time ago, and I'm no longer sure what I did and why when committing the previous 'fix' - the one that the new patch is obviously derived from.
Main problem: The custom field dictionary never has a key 'optional'
. It will always always return False
. It must be some typo, or reality distortion that has somehow worked well for me over the years.
The plugin badly needs unit tests...
comment:7 Changed 13 years ago by
Replying to osimons:
Main problem: The custom field dictionary never has a key
'optional'
. It will always always returnFalse
. It must be some typo, or reality distortion that has somehow worked well for me over the years.
In Trac 0.11-stable and 0.12-stable, custom field dictionary has 'optional'
key when the field type is 'select' and the field options include empty string.
trac.ini;
[ticket-custom] dropdown = select dropdown.label = ドロップ dropdown.options = |one|two dropdown.order = 0 dropdown.value = one
jun66j5@gotanda:580$ ~/virtualenv/trac-0.11-stable/bin/python Python 2.4.3 (#1, May 5 2011, 16:39:09) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> >>> from trac.env import open_environment >>> env = open_environment('/home/jun66j5/var/trac/0.11-stable') >>> from trac.ticket.api import TicketSystem >>> >>> ticketsys = TicketSystem(env) >>> custom_fields = ticketsys.get_custom_fields() >>> custom_fields [{'options': [u'one', u'two'], 'name': u'dropdown', 'type': u'select', 'optional': True, 'order': 0, 'value': u'one', 'label': u'\u30c9\u30ed\u30c3\u30d7'}] >>> >>> custom_fields[0]['name'] u'dropdown' >>> custom_fields[0]['options'] [u'one', u'two'] >>> custom_fields[0]['optional'] True >>>
comment:8 Changed 13 years ago by
Resolution: | → fixed |
---|---|
Status: | reopened → closed |
(In [10368]) CustomFieldAdminPlugin: Finally got the "optional options" issue of select fields figured out. Closes #1834.
Turned out that creating and updating the field worked fine, but when changing field order all fields are deleted and recreated with new order - which did not properly account for the the possibility of the field being supplied with an 'optional'
key by the TicketSystem
.
Wired up a test suite with tests that confirm that things work - and it should make it easier to look into issues in the future (in theory...).
comment:9 Changed 13 years ago by
Thanks for refreshing my memory, Jun :-) Hope you can confirm that things work as expected with latest from repository.
Just noticed the ticket - sorry! :-)
Have looked into it, and you are right - an empty first line (optional) disappears when editing the a select field.
I have updated the plugin through [2652], and it seems to work ok now. Closing the ticket, but please reopen my fix fails to solve it for you.