问题
I have a form.Form whose interface has a field that is a AutocompleteFieldWidget. (none)
is displayed because the field is not required. There is a glitch where (none)
will remain selected even if the user hits another radio button.
Parent = schema.Choice(title=u'Parent Object',
source=ParentSourceVocabSourceBinder(),
required=False,
default=None)
The field is bound to an object class acting as a vocabulary. The object has the required functions. The search function searches for records of a mapped table based on the query from the textbox the user enters information into and the __contains__
, getTerm
, getTermByToken
functions search for the matching record they require.
class ParentSourceVocab(object):
implements(IQuerySource)
vocabulary = SimpleVocabulary([])
session = None
def __contains__(self, term):
"""If term is None, set self.vocabulary equal to empty vocabulary and return none
"""
"""Else make fill the self.vocabulary with the found result and return SimpleTerm with result from running query
"""
def getTerm(self, value):
"""If value is None, set self.vocabulary equal to empty vocabulary and return none
"""
"""Else make fill the self.vocabulary with the found result and return SimpleTerm with result from running query
"""
def getTermByToken(self, token):
"""If token is None, set self.vocabulary equal to empty vocabulary and return none
"""
"""Else make fill the self.vocabulary with the found result and return SimpleTerm with result from running query
"""
def search(self,query_string):
if len(query_string) > 0:
q_string = query_string.strip('"').strip("'")
simples =[]
searchResults="""Query function"""
for result in results:
concat_string = """concatenated string for title"""
simples.append(SimpleTerm(title=result.obj_name,value=obj_id,token=obj_id)
self.vocabulary = SimpleVocabulary(simples)
return simples
else:
self.vocabulary = SimpleVocabulary([])
return None
class ParentSourceVocabSourceBinder(object):
implements(IContextSourceBinder)
def __call__(self, context):
return ParentSourceVocab(context)
One thing I did notice is that if the user does click (none)
, the form will recognize the (none)
value was clicked, but if a value from the search results was clicked, it will remain clicked, despite it knowing (none)
was selected. Its almost as if the (none)
and the search result radio buttons belong to two different "sets."
Am I misunderstanding how this widget works? Or is there something wrong with my javascript?
来源:https://stackoverflow.com/questions/28505910/plone-in-an-autocompletefieldwidget-how-can-i-fix-a-glitch-where-none-is-st