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

Validate () of FormField #2237

Closed
piyushporwal6795 opened this issue Jun 19, 2018 · 8 comments
Closed

Validate () of FormField #2237

piyushporwal6795 opened this issue Jun 19, 2018 · 8 comments

Comments

@piyushporwal6795
Copy link

Rasa Core version: 0.9.3

Python version: 3.5

Operating system: Windows 10

Issue: How to use validate() of FormField ?

@tannn
Copy link

tannn commented Jun 19, 2018

There is information for validation in the documentation.

@piyushporwal6795
Copy link
Author

I am ain't getting it exactly. How we will use?

@tannn
Copy link

tannn commented Jun 19, 2018

Below is an example implementation if you would like to validate that the user is entering a valid color. Any entry that doesn't match in the if statement would return None.

from rasa_core.actions.forms import FormAction 

class CustomFormActionColorValidation(FormAction):
    def validate(self, value):
        if value is not None:
            if value == "red":
                return value
            elif value == "blue":
                return value
            elif value == "green":
                return value
            elif value == "yellow":
                return value
            elif value == "purple":
                return value
            elif value == "black":
                return value
            elif value == "white":
                return value
            elif value == "magenta":
               return value
        return None

@piyushporwal6795
Copy link
Author

Okay thanks, will try and get back to you if I face any issues further

@Egalite123
Copy link

Pardon for duplicating the same question. I think, this is a better place.
Will it be possible to keep the validate function outside the core unit (within forms.py) and make it part of custom code?
Though this is working, it could lead to a mess. Imagine I am developing multiple bots and have to write all validations in a single unit. Possibly, some unnecessary code could creep into the master!
Thanks for considering.

@tannn
Copy link

tannn commented Jun 21, 2018

@Egalite123 Yes, in that case you can create the class in the directory you would like to use it, and import it when necessary. There is no requirement for adding files to the core code.

@stale
Copy link

stale bot commented Sep 19, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale
Copy link

stale bot commented Sep 29, 2018

This issue has been automatically closed due to inactivity. Please create a new issue if you need more help.

@stale stale bot closed this as completed Sep 29, 2018
@tmbo tmbo transferred this issue from RasaHQ/rasa_core Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants