You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can also interact with your `form` class instance from the widget template:
@@ -509,24 +527,26 @@ You can override widget templates as instructed for `z3c.form`.
509
527
You might want to customize this widget frame for your own form.
510
528
Below is an example of how to do it.
511
529
512
-
Copy [`widget.pt`](https://github.com/plone/plone.app.z3cform/blob/master/plone/app/z3cform/templates/widget.pt) to your own package, and edit it.
530
+
Copy [`widget.pt`](https://github.com/plone/plone.app.z3cform/blob/master/plone/app/z3cform/templates/widget.pt) to your own package, rename it as ``demo-widget.pt``and edit it.
513
531
514
-
Then add the following code to `configure.zcml`.
532
+
Then add the following code to `configure.zcml`. Remember to fix the path of the template according to your own paths.
515
533
516
534
```xml
517
535
<browser:page
518
536
name="ploneform-render-widget"
519
537
for=".demo.IDemoWidget"
520
538
class="plone.app.z3cform.templates.RenderWidget"
521
539
permission="zope.Public"
522
-
template="demo-widget.pt"
540
+
template="path/to/template/demo-widget.pt"
523
541
/>
524
542
525
543
```
526
544
527
545
Then create a new marker interface in Python code.
528
546
529
-
```python
547
+
```{code-block} python
548
+
:linenos:
549
+
530
550
from zope.interface import Interface
531
551
532
552
@@ -536,7 +556,9 @@ class IDemoWidget(Interface):
536
556
537
557
Then apply this marker interface to your widgets in `form.update()`.
538
558
539
-
```python
559
+
```{code-block} python
560
+
:linenos:
561
+
540
562
from zope.interface import alsoProvides
541
563
542
564
class MyForm(...):
@@ -555,7 +577,9 @@ You can combine several widgets into one with `z3c.form.browser.multil.MultiWidg
555
577
556
578
The following example shows how to create an input widget with minimum and maximum values.
557
579
558
-
```python
580
+
```{code-block} python
581
+
:linenos:
582
+
559
583
import zope.interface
560
584
import zope.schema
561
585
from zope.schema.fieldproperty import FieldProperty
@@ -582,34 +606,46 @@ class MinMax(object):
582
606
registerFactoryAdapter(IMinMax, MinMax)
583
607
584
608
585
-
field = zope.schema.Object(
586
-
__name__="minmax",
587
-
title=label,
588
-
schema=IMinMax,
589
-
required=False
590
-
)
609
+
class IMyFormSchema(zope.interface.Interface):
610
+
611
+
my_combined_field = zope.schema.Object(
612
+
__name__="minmax",
613
+
title=label,
614
+
schema=IMinMax,
615
+
required=False
616
+
)
617
+
591
618
```
592
619
593
-
Then you mark the widget in `updateWidgets()`:
620
+
Then you set the {guilabel}`my_combined_field`widget template in `updateWidgets()`:
0 commit comments