Giter Club home page Giter Club logo

plone.formwidget.autocomplete's Introduction

Introduction

plone.formwidget.autocomplete is a z3c.form widget for use with Plone. It uses the jQuery Autocomplete widget, and has graceful fallback for non- Javascript browsers.

There is a single-select version (AutocompleteFieldWidget) for Choice fields, and a multi-select one (AutocompleteMultiFieldWidget) for collection fields (e.g. List, Tuple) with a value_type of Choice.

When using this widget, the vocabulary/source has to provide the IQuerySource interface from z3c.formwidget.query and have a search() method.

plone.formwidget.autocomplete's People

Contributors

agitator avatar davisagli avatar do3cc avatar dukebody avatar esteele avatar gaudenz avatar gforcada avatar hannosch avatar izak avatar jensens avatar jone avatar krissik avatar laulaz avatar lentinj avatar lrowe avatar mauritsvanrees avatar mitakas avatar mjpieters avatar optilude avatar petschki avatar thet avatar vincentfretin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

plone.formwidget.autocomplete's Issues

Value not saved (multilingual?)

Possibly related to plone.app.multilingual; at least I only tested it there. Tired of bug hunting now, but let me at least put down some notes.

Setup scenario:

  1. Take plone.app.multilingual branch 1.x (Plone 4.3) from github, run its bootstrap and buildout.
  2. Create Plone Site, install p.a.multilingual, setup two languages. I pick Dutch and English.
  3. Create Dutch page.
  4. Create a second page, still in Dutch. (We will pick this page as English translation later, so we would have wanted to create an actual English page in the English language, but there is a problem unrelated to plone.formwidget.autocomplete there.)
  5. Return to the first Dutch page
  6. Click Actions -> Add Translations.

Now the problem:
A. Use the browse button (contenttree widget) to select the second page, see that a radio button is added in the original form showing the selected page, and submit the form and all is well: the two documents are now related.
B. Instead use the autocomplete input to select the second page, see that a radio button is added in the original form showing the selected page, and submit the form and all is not well: no relation has been added.

I have checked, and the radio button that is added in both these cases is exactly the same, in my case:

<input type="radio" checked="checked" name="form.widgets.content" id="form-widgets-content-0" title="None" value="/Plone/nl/soon-to-be-english-page-created-in-dutch-site" class="contenttree-widget required relationchoice-field">

So somehow the autocomplete widget does not correctly save the value.

User security context is absent from AJAX call

When utilizing the JavaScript AJAX call to a vocabulary that is sensitive to a logged in user's permissions (i.e. a vocabulary whose terms are based on catalog searches to ACL-restricted content), the AJAX call fails due to LookupError (my code). When researching the issue, I found that the request context is the Anonymous user instead of the user that is actually logged in.

The widget works fine (as expected) when not using JavaScript. Here's the URL that is causing the issue

http://localhost:8080/Plone/people/users/aliceheimbach/@@edit/++widget++form.widgets.business/@@autocomplete-search?q=cof&limit=10&timestamp=1448484747073

Why, when going to this view, would my logged in user become 'Anonymous' instead of what they actually are authenticated as?

AutocompleteMultiFieldWidget with required=True fails

Provided plone.formwidget.autocomplete.widget.AutocompleteMultiFieldWidget does fail to validate required field.

I wanted to create a RelationList field with at least one related item. Possible the easiest way to reproduce is to:

  1. Create a "dummy" Dexterity content type with plone.app.relationfield.behavior.IRelatedItems behavior enabled.
  2. Go into plone.app.relationfield.behavior.py and:
    • do change relatedItems field to required=True
    • add widget AutocompleteMultiFieldWidget in the schema to relatedItems field with plone.autoform.directives

What happens:
It is possible to create a new "dummy" content with no related items at all.

Expected behavior:
Not be able to create "dummy" unless there is at least one related items set.

Note:
Maybe the problem is much deeper, since I'm able to create the "dummy" without step 2. I'm also not getting validation error if I go TTW:

  • Dexterity Content Types > Add new content type > "Fruits"
  • Add new field > "Fruits" + MultiChoice + required checked
  • "Fruits" settings > values: apples, oranges

image

  • create a new "Fruits" with no fruits selected ...

question: QuerySourceCheckboxWidget subform behavior

I am trying to implement this widget and getting some odd behavior in Plone 5.2 that appears to be because of how QuerySourceCheckboxWidget (from which this widget inherits) is built.

My setup is a standard 5.x Plone form that inherits from plone.autoform.form.AutoExtensibleForm and z3c.form.form and uses a zope schema.

directives.widget(authors_all_names=AutocompleteMultiFieldWidget)
authors_all_names = schema.List(
    title=_("Author"),
    required=False,
    value_type=schema.Choice(source=AuthorSource())
)

The view template displays the rendered form as well some search results. Before the form is submitted the behavior works as expected. After a search is performed, the rendered form includes a "search" button on the field's fieldControls section and typing in the input box no longer prompts any js. The "search" button seems to be coming from QuerySubForm.

This behavior is so odd that I assume I either implemented something wrong or this widget is not meant to be used in cases where the value is set from request data.

On radio inputs ':list' should not be appended to name attribute

Form field radio button inputs are rendered without :list on the name (apart from the 'novalue' option on non required fields but that is a separate issue with z3c.formwidget).
New options added via js should therefore not have :list added to the name.
The name attributes of the inputs do not match so you cannot deselect the original value.

screen shot 2013-08-28 at 14 32 16

NOVALUE LookupError on RelationChoice field

I get the following error, if i try to setup AutocompleteSelectionWidget for a RelationChoice field.
It seems related to:

Maybe we need to fix that Widget too, see:

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.z3cform.layout, line 66, in __call__
  Module plone.z3cform.layout, line 60, in update
  Module z3c.form.form, line 161, in render
  Module zope.browserpage.viewpagetemplatefile, line 51, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module zope.pagetemplate.pagetemplate, line 240, in __call__
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 852, in do_condition
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 821, in do_loop_tal
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 888, in do_useMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 821, in do_loop_tal
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 533, in do_optTag_tal
  Module zope.tal.talinterpreter, line 518, in do_optTag
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
  Module zope.tales.tales, line 696, in evaluate
   - URL: /home/maik/develop/plone/.buildout/eggs/plone.app.z3cform-0.7.7-py2.7.egg/plone/app/z3cform/templates/macros.pt
   - Line 97, Column 46
   - Expression: <PathExpr standard:u'widget/@@ploneform-render-widget'>
   - Names:
      {'args': (),
       'context': <Library at /ub/ub-db/1>,
       'default': <object object at 0xb75116d0>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': {},
       'request': <HTTPRequest, URL=http://localhost:8080/ub/ub-db/1/@@edit>,
       'template': <zope.browserpage.viewpagetemplatefile.ViewPageTemplateFile object at 0xb47c0dec>,
       'view': <plone.dexterity.browser.edit.DefaultEditForm object at 0xb148b58c>,
       'views': <zope.browserpage.viewpagetemplatefile.ViewMapper object at 0xb14b50cc>}
  Module zope.tales.expressions, line 217, in __call__
  Module Products.PageTemplates.Expressions, line 155, in _eval
  Module Products.PageTemplates.Expressions, line 117, in render
  Module Products.Five.browser.metaconfigure, line 479, in __call__
  Module zope.browserpage.viewpagetemplatefile, line 83, in __call__
  Module zope.browserpage.viewpagetemplatefile, line 51, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module zope.pagetemplate.pagetemplate, line 240, in __call__
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 858, in do_defineMacro
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 954, in do_defineSlot
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
  Module zope.tales.tales, line 696, in evaluate
   - URL: /home/maik/develop/plone/.buildout/eggs/plone.app.z3cform-0.7.7-py2.7.egg/plone/app/z3cform/templates/widget.pt
   - Line 37, Column 4
   - Expression: <PathExpr standard:u'widget/render'>
   - Names:
      {'args': (),
       'context': <AutocompleteSelectionWidget 'form.widgets.integrated_in'>,
       'default': <object object at 0xb75116d0>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': {},
       'request': <HTTPRequest, URL=http://localhost:8080/ub/ub-db/1/@@edit>,
       'template': <zope.browserpage.viewpagetemplatefile.ViewPageTemplateFile object at 0xb4a4974c>,
       'view': <Products.Five.metaclass.RenderWidget object at 0xb148bdcc>,
       'views': <zope.browserpage.viewpagetemplatefile.ViewMapper object at 0xb148bf4c>}
  Module zope.tales.expressions, line 217, in __call__
  Module zope.tales.expressions, line 211, in _eval
  Module plone.formwidget.autocomplete.widget, line 124, in render
  Module Products.Five.browser.pagetemplatefile, line 125, in __call__
  Module Products.Five.browser.pagetemplatefile, line 59, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module zope.pagetemplate.pagetemplate, line 240, in __call__
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
  Module Products.PageTemplates.Expressions, line 218, in evaluateStructure
  Module zope.tales.tales, line 696, in evaluate
   - URL: /home/maik/develop/plone/.buildout/eggs/plone.formwidget.autocomplete-1.2.7-py2.7.egg/plone/formwidget/autocomplete/input.pt
   - Line 3, Column 4
   - Expression: <PathExpr standard:u'view/renderQueryWidget'>
   - Names:
      {'args': (<AutocompleteSelectionWidget 'form.widgets.integrated_in'>,),
       'container': <Library at /ub/ub-db/1>,
       'context': <Library at /ub/ub-db/1>,
       'default': <object object at 0xb75116d0>,
       'here': <Library at /ub/ub-db/1>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': <Products.PageTemplates.Expressions.SafeMapping object at 0xb13995a4>,
       'request': <HTTPRequest, URL=http://localhost:8080/ub/ub-db/1/@@edit>,
       'root': <Application at >,
       'template': <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0xb4d730ec>,
       'traverse_subpath': [],
       'user': <PropertiedUser 'admin'>,
       'view': <AutocompleteSelectionWidget 'form.widgets.integrated_in'>,
       'views': <Products.Five.browser.pagetemplatefile.ViewMapper object at 0xb147fe0c>}
  Module zope.tales.expressions, line 217, in __call__
  Module Products.PageTemplates.Expressions, line 155, in _eval
  Module Products.PageTemplates.Expressions, line 117, in render
  Module z3c.formwidget.query.widget, line 212, in renderQueryWidget
  Module z3c.form.widget, line 153, in render
  Module zope.browserpage.viewpagetemplatefile, line 51, in __call__
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module zope.pagetemplate.pagetemplate, line 240, in __call__
  Module zope.tal.talinterpreter, line 271, in __call__
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 821, in do_loop_tal
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 531, in do_optTag_tal
  Module zope.tal.talinterpreter, line 513, in no_tag
  Module zope.tal.talinterpreter, line 343, in interpret
  Module zope.tal.talinterpreter, line 742, in do_insertStructure_tal
  Module zope.tales.tales, line 696, in evaluate
   - URL: /home/maik/develop/plone/.buildout/eggs/z3c.form-3.2.3-py2.7.egg/z3c/form/browser/radio_input.pt
   - Line 8, Column 4
   - Expression: <PythonExpr (view.renderForValue(item['value']))>
   - Names:
      {'args': (),
       'context': <Library at /ub/ub-db/1>,
       'default': <object object at 0xb75116d0>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': {},
       'request': <HTTPRequest, URL=http://localhost:8080/ub/ub-db/1/@@edit>,
       'template': <zope.browserpage.viewpagetemplatefile.ViewPageTemplateFile object at 0xb482ab6c>,
       'view': <AutocompleteSelectionWidget 'form.widgets.integrated_in'>,
       'views': <zope.browserpage.viewpagetemplatefile.ViewMapper object at 0xb13e57ec>}
  Module zope.tales.pythonexpr, line 59, in __call__
   - __traceback_info__: (view.renderForValue(item['value']))
  Module <string>, line 1, in <module>
  Module z3c.form.browser.radio, line 44, in renderForValue
  Module z3c.form.term, line 38, in getTermByToken
  Module zope.schema.vocabulary, line 133, in getTermByToken
LookupError: --NOVALUE--

Leverage ajaxQueue in order to gain abort() support

The current implementation of the widget makes it under some situations sluggish and unresponsive in particular with slow backend responses or fast typing.

The widget already uses jquery.autocomplete.js which has optional support for using ajaxQueue which would allow to abort a pending ajax request in favor of a more up-to-date query request.

So an improved usability might be accomplished by shipping the widget with ajaxQueue.

GS resource dependencies

please define JS resources after collective.js.jqueryui.custom.min.js in order to ensure sane resource delivery.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.