我有一个form.Form,其接口有一个AutocompleteFieldWidget字段。显示(none)
,因为该字段不是必需的。即使用户点击另一个单选按钮,也会出现一个小故障,(none)
将保持选中状态。
Parent = schema.Choice(title=u'Parent Object',
source=ParentSourceVocabSourceBinder(),
required=False,
default=None)
该字段绑定到充当词汇表的对象类。该对象具有所需的功能。搜索功能根据用户输入信息的文本框中的查询搜索映射表的记录,__contains__
,getTerm
,getTermByToken
函数搜索所需的匹配记录。
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)
我注意到的一件事是,如果用户点击(none)
,表单会识别出已点击的(none)
值,但如果点击了搜索结果中的值,则会保持点击状态尽管知道(none)
被选中了。它几乎就像(none)
和搜索结果单选按钮属于两个不同的“集合”。
我是否误解了这个小部件是如何工作的?或者我的javascript有问题吗?