Jump to content
mikejandreau

Validating input in trigger?

Recommended Posts

If I'm using a basic keyword trigger, is there any method I can use to validate the input?

 

For example, if I only want to allow numeric input, or if I want to validate email address formatting?

Share this post


Link to post

There's no way to tell Alfred not to accept the input if you're using a Keyword, no. Alfred doesn't run any of your code until after the user hits ↩. The best you can do is show an error notification and re-open Alfred from your script.

 

If you want "live" validation, you need to use a Script Filter. Alfred calls your script while the user is entering their query, so you can validate the input and show an "invalid input" message in the results if need be.

 

For example, my MailTo workflow validates email addresses this way.

 

 

Share this post


Link to post

Looks like that'll work. I've thrown a Script Filter in line after the ask for the email address with regex in it.

 

I then fork for regex matches and regex doesn't match.

 

The only issue I see is that I can't loop back from my Script Filter to the Input asking for the email.

 

Ideally I'd like to do: Ask for Email → Regex (script filter) says it doesn't match →  Show a Notification →  Loop back to Ask for Email step. I don't seem to be able to connect my Regex failure Script Filter back to the input. Am I missing something there?

Share this post


Link to post

You can't connect a workflow directly to its own beginning. You have to call it via an External Trigger.

 

Also, you don't put the Script Filter downstream of the Keyword that asks for an email, you use it instead of the Keyword. The Script Filter is run as you're entering the query and provides instant feedback on whether or not the input is valid and doesn't allow the workflow to proceed until it is.

 

If you have any further questions, please upload a copy of the workflow somewhere and post a link: it's very difficult to diagnose issues with a workflow I've never seen. Screenshots aren't enough.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...