Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Form Docs Section Update #10734

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/10536.doc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update dynamic form behaviour docs section with an example on how to override `required_slots` in case of removal of a form required slot.
31 changes: 30 additions & 1 deletion docs/docs/forms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ By default Rasa Open Source will ask for the next empty slot from the slots
listed for your form in the domain file. If you use
[custom slot mappings](forms.mdx#custom-slot-mappings) and the `FormValidationAction`,
it will ask for the first empty slot returned by the `required_slots` method. If all
slots in `required_slots` are filled the form will be be deactivated.
slots in `required_slots` are filled the form will be deactivated.

If needed, you can update the required slots of your form dynamically.
This is, for example, useful when you need further details based on how
Expand Down Expand Up @@ -388,6 +388,35 @@ class ValidateRestaurantForm(FormValidationAction):
return additional_slots + domain_slots
```

If conversely, you want to remove a slot from the form's `required_slots` defined in the domain file under certain conditions,
you should copy the `domain_slots` over to a new variable and apply changes to that new variable instead of directly modifying
`domain_slots`. Directly modifying `domain_slots` can cause unexpected behaviour. For example:

```python
from typing import Text, List, Optional

from rasa_sdk.forms import FormValidationAction

class ValidateBookingForm(FormValidationAction):
def name(self) -> Text:
return "validate_booking_form"

async def required_slots(
self,
domain_slots: List[Text],
dispatcher: "CollectingDispatcher",
tracker: "Tracker",
domain: "DomainDict",
) -> List[Text]:
updated_slots = domain_slots.copy()
if tracker.slots.get("existing_customer") is True:
# If the user is an existing customer,
# do not request the `email_address` slot
updated_slots.remove("email_address")

return updated_slots
```

### The requested_slot slot

The slot `requested_slot` is automatically added to the domain as a
Expand Down