What I’m trying to do
Modal forms Plugin
Using this template,
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('insert-badge');
tR += result.asString("`[!!{{type}}:{{type}}]`")
_%>
If I insert this I get a form, which lets me choose one many predefined ‘type’ of badge (note, info, etc.) which gets inserted.
For example;
Selecting ‘note’ will give me
`[!!note:note]`
Which inserts a 'note type badge with the label “note”.
What I want to do, is add an additional field to the modal form which will optionally allow me to add a custom label in the form itself.
Things I have tried
I tried this
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('insert-badge');
if custom-label = true
tR += result.asString("`[!!{{type}}:{{label}}]`")
else
tR += result.asString("`[!!{{type}}:{{type}}]`")
_%>
But it didn’t work.
The modelforms documentation didn’t have any info on using the results from the toggle (or I missed it).
Any advice?
Additional info;
The Badges plugin syntax is this
`[!!<badge type>:<label>]`
Anwen
January 22, 2024, 8:47am
3
How is defined the custom-label variable ?
I think the simplest way is to first retrieve the field values with get and then build the strings.
Something like that:
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('insert-badge');
type = result.get("type");
label = result.get("label");
if (label){
tR += "`[!!" + type + ":" + label + "]`"}
else{
tR += "`[!!" + type + ":" + type + "]`"}
_%>
1 Like
Thank you!
That helped get around needing to use the toggle, but now its adding extra stuff for some reason.
I’m getting
`[!!["Note"]:["Note"]]`
Where I expected
`[!!Note:Note]`
Adding a label, gets me
`[!!["Note"]:label]`
so the 'label key is working correctly. Only the ‘type’ key is adding extra [" "]
. Looking the script, I can’t figure it out.
Edit: switching out the results for the older format I used works, so the final script is;
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('insert-badge');
type = result.get("type");
label = result.get("label");
if (label){
tR += result.asString("`[!!{{type}}:{{label}}]`")}
else{
tR += result.asString("`[!!{{type}}:{{type}}]`")}
_%>
Still I’d like to know what went wron with the other one if you know?
Anwen
January 22, 2024, 1:48pm
5
Weird, This acts as a list.
And this ? :
<%*
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('insert-badge');
type = result.get("type");
label = result.get("label");
if (label){
tR += "`[!!" + type[0] + ":" + label + "]`"}
else{
tR += "`[!!" + type[0] + ":" + type[0] + "]`"}
_%>
That seems to be inputting a single element from [“type”] according to the number.
0 = [
1 = "
2 = first letter of the type ( N if Note, t if tldr, etc.)
Don’t know how to input multiple characters, and if I do I’d be limited to types with same amount of characters in this case.
Do you know how to use the toggle from Modal forms?
And to clarify, in the if(label)
part any input for the label acts as boolean true?
system
Closed
January 30, 2024, 4:26am
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.