Skip to content

Commit

Permalink
Update form widgets docs for additional widgets (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jul 23, 2021
1 parent e8a6edc commit 151f906
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions docs/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,30 @@ Also, you understood that `Form` also accepts `Field` objects as arguments.

Customizing forms
-----------------

Good applications also need good styles. This is why Emmett forms allows you to
set a specific style with the `formstyle` attribute. But how should you edit the
style of your form?

Well, in Emmett, the style of a form is decided by the `FormStyle` class.

### Additional widgets

Emmett's default `FormStyle` also provides some additional widgets you can use in place of the default ones.

#### Radio widget

Under default circumstances, Emmett will produce a `select` tag for those fields which should be part of a pre-defined set. In case you prefer to generate inputs of type radio, you can use `FormStyle.widget_radio`:

```python
form = await Form({
'type': Field(
validation={'in': ['type1', 'type2']},
widget=FormStyle.widget_radio
)
})
```

### Creating your style
*sub-section under development*

Expand Down
10 changes: 10 additions & 0 deletions docs/orm/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,16 @@ And you can also use the `widget` parameter of `Field` class:
started = Field.datetime(widget=my_custom_widget)
```

#### Additional widgets

In case you want to use [additional widgets](../forms#additional-widgets) in `FormStyle` class, simply pass the relevant method in `form_widgets` dictionary:

```python
form_widgets = {
'field': FormStyle.widget_radio
}
```

The setup helper
----------------
Sometimes you need to access your model attributes when defining other features, but, until now, we couldn't access the class or the instance itself. To avoid this problem, you can use the `setup` method of the model:
Expand Down

0 comments on commit 151f906

Please sign in to comment.