Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank if null with result.asString ? #129

Closed
juusan opened this issue Nov 9, 2023 · 1 comment · Fixed by #159
Closed

Blank if null with result.asString ? #129

juusan opened this issue Nov 9, 2023 · 1 comment · Fixed by #159

Comments

@juusan
Copy link

juusan commented Nov 9, 2023

Hello !

What a wonderful plugin ! Thanks for working hard on it.

Do you know if there is a way to output nothing if we submit no value into the prompt ? Here is an exemple :

const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('climateLogForm');
tR += result.asString('AC_probe_T_avg :: {{AC_probe_T_avg}}') + '\n';

With this snippet, if I enter 25 it renders like : AC_probe_T_avg :: 25
But if I let the prompt empty and submit it, it renders AC_probe_T_avg :: {{AC_probe_T_avg}}
I would like to render it just like AC_probe_T_avg ::

Is there any way to do it ?
Thank you so much !

@danielo515
Copy link
Owner

Thank you for your kind words! And for using it
Sadly, there is no way yet. I've been thinking a lot about streamlining the usage of the result and the API, and this specific case was already in my mind.

As a workaround, you can currently do this:

const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('climateLogForm');
const data = result.getData()
if (data.AC_probe_T_avg){
    tR += `AC_probe_T_avg :: ${AC_probe_T_avg}\n`;
}

How would it look like something like this (this is the idea I have in mind)

const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('climateLogForm');
tR += result.map('AC_probe_T_avg', (value) => `AC_probe_T_avg :: ${value}`)

Here, if the value of AC_probe_T_avg is undefined, then the map will return an empty string, but if the value exists, then it will use your function to transform it to whatever you want

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment