Skip to content

Commit 5375d15

Browse files
committed
Fix autocomplete field bug
Improves a regex that is used in the clean() method of AjaxForeignKeyNewformField. There are three possible states for the data in such a field after a form submission: - The field contains raw text. - An autocomplete option was correctly selected, and the value is an integer id. - An autocomplete option was incorrectly selected, and the value is something that looks like "Foo Bar (17)", where the number is the object's integer id. The clean() method attempts to catch and correct the last case with a regex. But that regex captured things that it shouldn't have, such as (encountered on the Stanford site) "k12 online school". The improved regex only matches the field when the number is in parentheses, at the very end of the string.
1 parent 5edcfd4 commit 5375d15

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

esp/esp/db/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.utils.safestring import mark_safe
66
import re
77

8-
get_id_re = re.compile('.*\D(\d+)\D')
8+
get_id_re = re.compile('.*\((\d+)\)$')
99

1010
class AjaxForeignKeyFieldBase:
1111

0 commit comments

Comments
 (0)