The API docs for the Form.Field.Option
constructor show its arguments as:
(
key: String ,
displayName: String or null ,
options: Array of Object,
names: Array of String or null ,
selected: Object or null ,
nullOptionTitle: String or null
)
It turns out (macOS OF OmniFocus 3.11) that if we pass an empty string as the last argument, we obtain not an error message but an application crash.
new Form.Field.Option(
'choice', // key
'Testing', // displayName
['Alpha', 'Beta', 'Gamma'], // options
null,
''
);
Some other permutations of those last two arguments also seem to harvest crashes, so there may at some point (if time and resource come to hand) be room for additional type-safety and error messaging somewhere in there :-)
In the meanwhile, proceed with caution.
JS Source
/*{
"author": "draft8",
"targets": ["omnifocus"],
"type": "action",
"identifier": "com.etc.testCrash",
"version": "0.1",
"description": "Minimal code for Field.Option crash",
"label": "FieldOptionCrashTest",
"mediumLabel": "FieldOptionCrashTest",
"paletteLabel": "FieldOptionCrashTest",
}*/
(() => Object.assign(
new PlugIn.Action(selection => {
// main :: IO ()
const main = () => {
const
viable = new Form.Field.Option(
'choice', // key
'Testing', // displayName
['Alpha', 'Beta', 'Gamma'] // options
),
variant2 = new Form.Field.Option(
'choice', // key
'Testing', // displayName
['Alpha', 'Beta', 'Gamma'], // options
null,
null
),
crashesOmniFocus1 = new Form.Field.Option(
'choice', // key
'Testing', // displayName
['Alpha', 'Beta', 'Gamma'], // options
null,
''
),
crashesOmniFocus2 = new Form.Field.Option(
'choice', // key
'Testing', // displayName
['Alpha', 'Beta', 'Gamma'], // options
[],
null
);
// userDialog([viable])('Selection')(x => x);
userDialog([viable])(
'Selection'
)(x => x);
};
// ------------------- OMNIJS --------------------
// userDialog :: [Form.Field] ->
// String -> values -> () -> Promise
const userDialog = fields =>
// General constructor for omniJS dialogs,
// where f is a continuation function
// in which a dialog result
// is bound to the function argument.
prompt => f => fields.reduce(
(form, field) => (
form.addField(field),
form
), new Form()
)
.show(prompt, 'OK')
.then(f);
return main();
}), {
validate: selection => true
}
))();