Plone - In an AutocompleteFieldWidget, how can I fix a glitch where (none) is still selected despite another selected?

喜夏-厌秋 提交于 2019-12-10 09:42:14

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!