Custom widget to manage complex json data stored into a text field
Project description
z3c.form widget to manage a json field.
Features
Customizable schema
Usage
You need to set the widget to needed fields into your form instance:
from collective.z3cform.jsonwidget.browser.widget import JSONFieldWidget from zope.interface import Interface from zope import schema class IMyJsonSchema(Interface): first = schema.TextLine( title='first field', required=True, ) second = schema.List( title="second field", required=False, value_type=schema.TextLine(), ) class IFormSchema(Interface): my_json_field = schema.SourceText( title="The field with some stored json values" ) class MyForm(Form): ... schema = IFormSchema fields = field.Fields(IFormSchema) fields["my_json_field"].widgetFactory = JSONFieldWidget def updateWidgets(self): """ """ super(MyForm, self).updateWidgets() self.widgets["my_json_field"].schema = IMyJsonSchema
With this configuration, we are setting JSONFieldWidget widget to my_json_field field and setting the fields schema defined in IMyJsonSchema interface.
In the field are stored a list of json objects where each object has a set of fields defined in the schema.
For example for the given configuration, we are going to store into the field something like:
[ { "first": "a string", "second": [1,2,3,4] }, { "first": "another string", "second": ["a", "b", "c"] }, ]
Translations
This product has been translated into
Italian
Installation
Install collective.z3cform.jsonwidget by adding it to your buildout:
[buildout] ... eggs = collective.z3cform.jsonwidget
and then running bin/buildout
Contribute
Credits
Developed with the support of Regione Emilia Romagna;
Regione Emilia Romagna supports the PloneGov initiative.
0.2.1 (2021-05-18)
Add alt text on buttons
Add locales for a11y hints [nzambello]
0.2.0 (2021-05-17)
Add link and path to referenced items [nzambello]
Fix TextLine field. [cekk]
0.1.0 (2021-02-09)
Initial release. [cekk]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for collective.z3cform.jsonwidget-0.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6058bb8ff01d6cf125946e2f16f248c94cba08cdd0c6c5afe244f592c77eb75 |
|
MD5 | 110a3e2420cd5815fe0cd42f33abc590 |
|
BLAKE2b-256 | 7600fcf9cba6cd06419c6a4cc434e2d949a08066a047eb87ee9fa5a449c734b6 |