.. -*-doctest-*-

=============
List Criteria
=============

The ListFormCriterion is provided for rendering lists on the search
form.

We start with a topic.

    >>> foo_topic = self.folder['foo-topic-title']

Open a browser as an anonymous user.

    >>> from Products.Five.testbrowser import Browser
    >>> from Products.PloneTestCase import ptc
    >>> browser = Browser()
    >>> browser.handleErrors = False

Add a list criterion for the subject/keywords.

    >>> foo_topic.addCriterion(
    ...     'Subject', 'ListFormCriterion')
    <ListFormCriterion at
    /plone/Members/test_user_1_/foo-topic-title/crit__Subject_ListFormCriterion>

Designate the criterion's field as a form field.

    >>> crit = foo_topic.getCriterion('Subject_ListFormCriterion')
    >>> crit.setFormFields(['value'])
    
The values set on the criterion are the default values checked on the
search form.

    >>> crit.setValue(['bah'])

When viewing the collection in a browser lists will be rendered
for the field with the default values selected.

    >>> browser.open(foo_topic.absolute_url())
    >>> ctrl = browser.getControl(
    ...     name='form_crit__Subject_ListFormCriterion_value:lines')
    >>> ctrl
    <Control name='form_crit__Subject_ListFormCriterion_value:lines'
    type='textarea'>
    >>> ctrl.value
    'bah'

By default the criterion values determine the search results.

    >>> browser.getLink('Bar Document Title')
    <Link text='Bar Document Title'
    url='http://nohost/plone/Members/test_user_1_/bar-document-title'>
    >>> browser.getLink('Baz Event Title')
    Traceback (most recent call last):
    LinkNotFoundError

Also note that criteria that use a 'value' field as the primary search
value do not render the label for the value field as it would be
redundant.

    >>> 'Values</label>' in browser.contents
    False
    >>> ('form_crit__Subject_ListFormCriterion_value_help'
    ...  in browser.contents)
    False

Change the checked values and search

    >>> form = browser.getForm(name="formcriteria_search")
    >>> form.getControl(
    ...     name='form_crit__Subject_ListFormCriterion_value:lines'
    ...     ).value = 'quux'
    >>> form.getControl(name='submit').click()

Now the default has been overriden by the submitted query.

    >>> browser.getLink('Bar Document Title')
    Traceback (most recent call last):
    LinkNotFoundError
    >>> browser.getLink('Baz Event Title')
    <Link text='Baz Event Title'
    url='http://nohost/plone/Members/test_user_1_/baz-event-title'>
