Validate what user input in a flow card

Hi,
I’m developing Local API App.
I was wondering if there was a way (a method, or, better, a piece of documented code) to validate the fields entered by users through Flows (normal and advanced).
My intent is to check that the text fields entered have certain characteristics (simple controls, such as startswith or regex)
On the documentation I haven’t found anything about it.
Is there a method to validate what user input in a flow card input?

What should be a valid input? JSON in general? Then I would parse the string with JSON.parse() and check if it doesn’t throw an error.
If it’s free text or could be XML, too, then it’s hard to decide about the content type.
If you are using content-type in the response, you could add a optional enum field in the flow card where the user can select a content-type (application/json…). And depending that you can parse the content.

You’re right, sorry, I didn’t make myself clear.

I know how to validate a data that comes to me through a user input, however I would like a function that would allow me to validate it when saving the Flow or when an input is just written in the flow, and give me the capability to immediately report the error to the user.

At the moment, if during the creation phase the user enters “invalid” data, the Flow allows it to insert that data because it distinguish between a string or a number, but does not allow me “on the fly” to provide a validations chosen by me (developer) more complex rather then the type of data entered.

Ah, at flow creation time…
I don’t think you can interact. That’s default Homey core/GUI and just text fiels.

The only thing you can do is throwing a error in the flow so the User can write the error output to timeline.

1 Like

You can add a Regex to validate an user input, but don’t think Regex is extensive(?) enough to validate if the input is valid JSON.

EDIT: hmmm, maybe there is one big one :sweat_smile: not sure it will fit the Regex flag though.

Regex in flow definition to check user input in flow editor?

Aah never mind… it was for device settings… I wonder why they didn’t do it for flow cards, or just not documentated .

Sorry for the spam, but had another idea that might be a bit difficult as it isn’t documented yet, the “code” input field, like HomeyScript uses has a build-in validator, and the code for HomeyScript is opensource, so perhaps you can take some inspiration there how it is used.

Thank you @RonnyW and @Caseda

I try to read something, however I would have to find a way to interact directly with the core of the flow part to be able to throw an exception for the user GUI.
I will keep you updated in case I find something useful.

If anyone has any other ideas, are welcome!

I thought you would have some magic things, a rabbit rabbit and a hat :slight_smile:

But yes, the code field sounds nice.

Line 14 you can try in your flow card.

1 Like