Current version : 0.22.0
Made in 🇫🇷 ◌ GitHubNPM

💡 Sept. Tip => use case input field filling mode

Should a use case input field be filled by the user or not ?

During this month of September 2025, we'll highlight various and interesting aspects of libmodulor.

Let's start with an example. Let's say we are building a use case that allows our users to report a bug :

interface ReportBugInput extends UCInput {
    description: UseCaseInputFieldValue<FreeTextLong>;
    screenshot: UseCaseInputFieldValue<File>;
    userAgent: UseCaseInputFieldValue<UserAgent>;
}

By default, a GUI target will expose this use case as follows :

+------------------------------------------+
| Description:                             |
| [______________________________________] |
| [______________________________________] |
| [______________________________________] |
+------------------------------------------+
| Screenshot: [ Choose File ]              |
+------------------------------------------+
| UserAgent:  [__________________________] |
+------------------------------------------+
|   [   Submit   ]        [   Cancel   ]   |
+------------------------------------------+

Here is the thing : it does not make much sense to ask the user for the userAgent as we can infer it from the context (i.e. the browser they're using).

This is where the fillingMode property is very handy. There are two possible values :

  • AUTO_PRE : Set programmatically on behalf of the user before submitting the use case
  • MANUAL (default) : Set manually by the user
export const ReportBugInputUCD: UCDef<
    ReportBugInputInput,
    ReportBugInputOPI0
> = {
    // ...
    io: {
        // ...
        i: {
            fields: {
                description: {
                    type: new TFreeTextLong(),
                },
                screenshot: {
                    type: new TFile(),
                },
                userAgent: {
                    fillingMode: UCInputFieldFillingMode.AUTO_PRE,
                    type: new TUserAgent(),
                },
            },
        },
        // ...
    },
    // ...
};

By using UCInputFieldFillingMode.AUTO_PRE for userAgent, we tell the target that it shouldn't display any form field for it. For example, in React, we would fill it when rendering <UCPanel /> like so :

<UCPanel
    // ...
    onInit={async (uc) => {
        uc.inputField('userAgent').setVal(navigator.userAgent);
    }}
    // ...
/>

Voilà c'est tout.