========================
zeam.form.ztk uri widget
========================

Simple case
===========

Setup
-----

We need first a schema with a URI field, and a content:

  >>> from zope import interface
  >>> from zope import schema
  >>> from zope.interface.verify import verifyObject

  >>> class ILink(interface.Interface):
  ...     uri = schema.URI(title=u"Location")

  >>> class Link(object):
  ...     pass
  >>> content = Link()

  >>> from zope.publisher.browser import TestRequest
  >>> request = TestRequest()

Field
-----

So now you can create a field, and get a URI field:

  >>> from zeam.form.base import Fields, Field
  >>> from zeam.form.base import interfaces

  >>> fields = Fields(ILink)
  >>> uri_field = fields['uri']
  >>> uri_field
  <URIField Location>

  >>> uri_field.title
  u'Location'
  >>> uri_field.required
  True
  >>> verifyObject(interfaces.IField, uri_field)
  True


Validation
~~~~~~~~~~

The field will only validate proper URIs:

  >>> uri_field.validate('https://github.com/thefunny42/Zeam-Form-ZTK', None)
  >>> uri_field.validate('Github', None)
  u'The URI is malformed.'

  >>> uri_field.validate('', None)
  u'Missing required value.'

  >>> uri_field.required = False
  >>> uri_field.validate('', None)

  >>> uri_field.required = True
  >>> uri_field.maxLength = 20
  >>> uri_field.validate('https://github.com/thefunny42/Zeam-Form-ZTK', None)
  u'The URI is too long.'
  >>> uri_field.validate('http://github.com', None)

  >>> uri_field.minLength = 15
  >>> uri_field.validate('http://g.com', None)
  u'The URI is too short.'


Widget
------

You have an associated widget::

  >>> from zeam.form.ztk import Widgets, FormData

  >>> Form = FormData(content, request)
  >>> Form.ignoreContent = False

  >>> URIWidgets = Widgets(
  ...     fields,
  ...     form=Form,
  ...     request=request)

  >>> URIWidgets.update()

  >>> URIWidget = URIWidgets['form.field.uri']
  >>> URIWidget
  <URIWidget Location>
  >>> print URIWidget.render() #doctest: +NORMALIZE_WHITESPACE
  <input type="url" value="" id="form-field-uri" class="field field-uri field-required"
         name="form.field.uri" required="required" />
