How to create an input form for multiple inputs?

Hi everyone!

I’ve been looking far and wide but without success, so allow me to share this question with you:

I’ve recently started logging various personal metrics via AFO – Thanks again @czottmann for your help here.

While this is working, I’m coming against a UX limitation:
As I have around 10 metrics at end of day, doing this via the native “ask for” Shortcuts action is really tedious as it opens again and again for each question.

My idea solution would be a one simple form containing all questions below each other. I don’t know if this is possible out of the box with shortcuts or with anyone knows of other apps that let you collect the input and then assign it to variables that I can then further process.

Thanks for any help and pointers!

(…and once I figured this out, I’ll try pulling health data directly from Apple health but that seems complicated)

My idea solution would be a one simple form containing all questions below each other. I don’t know if this is possible out of the box with shortcuts or with anyone knows of other apps that let you collect the input and then assign it to variables that I can then further process.

You’re basically asking for a form generator & presenter which can funnel your input back into a Shortcuts workflow, right? I’ve not seen any app that provides this. And I am not aware of any way to achieve that with built-in Shortcuts actions. I also checked the venerable Actions app (no relation) as well as Toolbox Pro, because if any app would over that functionality, it’d be one of those two, but to no avail.

Sorry.

Update: I’ve asked around on Mastodon, and lo and behold, @gluebyte@mastodon.social had an answer!

Use a built-in Dictionary action, set the keys to your questions, set the type to whatever, and set one value to the built-in “Ask Each Time” placeholder (enter the value field, right-click it, Insert VariableAsk Each Time. This will pop up the entire dictionary in a dialog when the workflow is executed, and allows you to fill in every available value. I’ve made a quick video:

Once you’ve filled out all the fields, the action will return a bog-standard dictionary which you can then dissect as usual.

Hope this helps!

Hi

I conducted some experiments with the idea of using an HTML form, which was posted by @davidbures@mstdn.social. in the same thread Carlo mentioned. His solution didn’t work on macOS, but it served as a good starting point for me to create a slightly different solution.

He proposed a shortcut that runs twice. The first time without any input. In this case it open an embedded HTML form in Safari that includes as well a submit button, which triggers the shortcut a second time with the values of the form fields. Since there is input this time, another branch of the if/then statements is executed.

For my solution, I created an HTML form page instead of using the embedded HTML, which looks like this:

Here is the code:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vital Signs Recording</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; }
        label { display: block; margin-top: 10px; }
        input, select { width: 100%; padding: 5px; margin-top: 5px; }
        button { margin-top: 20px; background-color: #4CAF50; color: white; border: none; padding: 10px; cursor: pointer; width: 100%; }
    </style>
</head>
<body>
    <h1>Vital Signs Recording</h1>
    <form id="vitalSignsForm">
        <label for="heartRate">Heart Rate (BPM):</label>
        <input type="range" id="heartRate" name="heartRate" min="40" max="180" value="70">
        <output for="heartRate"></output>

        <label for="bloodPressure">Blood Pressure (systolic/diastolic):</label>
        <input type="text" id="bloodPressure" name="bloodPressure" placeholder="120/80">

        <label for="temperature">Body Temperature (°C):</label>
        <input type="number" id="temperature" name="temperature" min="35" max="42" step="0.1" value="36.5">

        <label for="respiration">Respiration Rate (per minute):</label>
        <input type="range" id="respiration" name="respiration" min="10" max="30" value="15">
        <output for="respiration"></output>

        <label for="Mood">Mood:</label>
        <select id="Mood" name="mood">
            <option value="euphoric">Euphoric</option>
            <option value="neutral">Neutral</option>
            <option value="frustrated">Frustrated</option>
        </select>

        <button type="button" onclick="sendData()">Submit Data</button>
    </form>

    <script>

        // Updates the display of the slider values
        document.querySelectorAll('input[type="range"]').forEach(function(slider) {
            slider.nextElementSibling.value = slider.value;
            slider.oninput = function() {
                this.nextElementSibling.value = this.value;
            }
        });

    function sendData() {
        var form = document.getElementById('vitalSignsForm');
        var formData = new FormData(form);
        var jsonObject = {};

        for (var pair of formData.entries()) {
            jsonObject[pair[0]] = pair[1];
        }

        var jsonString = JSON.stringify(jsonObject);
        var shortcutURL = "shortcuts://run-shortcut?name=vital&input=" + encodeURIComponent(jsonString);
        window.location.href = shortcutURL;
}
    </script>
</body>
</html>

For testing purposes, the “Submit Data” button also sends the values as json. Since the data processing requires input, I leave it as it is for the moment.

The shortcut uses the beta version of the ‘Browser Action’. Currently (as of 10/14/2024), it does not work with Safari but is compatible with all other supported browsers. I haven’t found a way to handle the select options; perhaps Carlo has a tip on how to retrieve these value.

This is a first attempt to test the idea. In any case, I think it looks nicer than this dictionary popup! :wink:

The HTML page can remain local in the file system and can be opened with file://pathToHTML, or it can be accessed, as in my example, from a web server. The solution will not work on iOS/iPadOS because ‘Browser Action’ is a Mac-only extension for Shortcuts. However, in the next few days, I will investigate whether the JSON could be used on iOS/iPadOS.

I hope this is also a viable way to handle your request. With HTML, you have more flexibility in terms of UI elements; however, It could also be that Carlo still has some adjustments to make to Browser Actions. Nevertheless it works already with simple UI elements.

1 Like

First up – Big thank you @czottmann and @leif for getting back on this question!

@leif, I agree that doing it via a HTML looks a lot nicer than the what the Shortcuts produces – Thanks for putting all the documentation here.
My use case though is 95% iOS, so I’ll have to pass on this one for now.

Which brings me to the Dictionary route – Thanks @czottmann for asking around on Mastodon and making the video, I really appreciate it.
And exciting that there is a way to give the whole Dictionary out in one go for input.
I have to agree with @leif when it comes to design (not to mention that it is a little error-prone as it is not only the values you can chose but all Dictionary data) but great that it is in one screen!

This allows me to do my end of day a lot smoother – Thanks again!

@LikeShootingStars as promised I have spent some time to see if I can get my solution to work on iOS and iPad. One constraint: on iOS/iPadOS it doesn’t seem to be possible to open an HTML file stored in the iOS file system, it has to be accessed via a URL from a web server. Since the submit button in my HTML example also sends the data to the link as a json, I just need to find a way to process it there. This is easily possible using a dictionary that consumes the json input when it is created. Then, as before, the content of a note can be assembled and created with ‘Actions for Obsidian’ in Obsidian. This part can also be supplemented with health values, e.g. from the Health app. The link works on iOS/iPad/macOS, so no “browser actions” are needed for this use case, sorry @czottmann.
I also came up with the “ingenious” idea of no longer calling up the HTML in a web browser, but loading it as an iframe in Obsidian. Unfortunately, Obsidian refuses to execute the URI shortcut://. Does anyone have an idea how to get around this restriction? All the solutions I have tried so far have only worked in the browser and not as an iFrame in Obsidian.

1 Like

Star Trek's Captain James T. Kirk yelling "KHAAAN", angrily'

1 Like

@leif, thanks for spending time and seeing if you could get this to work on iOS/iPadOS!

Hearing your solution, my initial thought was also to run it via an iFrame (and then also making visually nicely integrate with Obsidian) but then I realised that it would not allow for what I had hoped:
My thinking of having the form pop up as I open the shortcut is to cut down on Obsidian opening time and to have a very simple input interface.
Running an iFrame would also feel a bit redundant: I’d open a note to change another (why not changing the other in the first place? [see also option 3 below]).

With that, I’m working right now with combination following three input options:

  1. Option: I have specific shortcuts that update a single property. I use this mainly for habit tracking. When I do a habit I hit the short cut and it updates the property.
  2. Option: I utilise the solution @czottmann sourced above. I use this for my morning and evening “check-in”. Here, it would be great to include the health data e.g. sleep duration, activity time but getting them out of the Health app seems cumbersome.
  3. Option: In my daily note template, I include all potential properties but without value. So if I need to add / adjust a value I can to that right there.

This works OK for me for now. Of course manually putting health data in is a little meh but OK for now.

Thanks again!

Sorry, I’m kind of busy at the moment, but …

Here, it would be great to include the health data e.g. sleep duration, activity time but getting them out of the Health app seems cumbersome.

… it isn’t, not really:

Under “Start Date”, you’ll probably want to add some extra filtering, like “type of sleep” or something (I remember Health can log the different sleep stages and whatnot).

HTH! :wink:

2 Likes