danielo515 / obsidian-modal-form

Define forms for filling data that you will be able to open from anywhere you can run JS
https://danielorodriguez.com/obsidian-modal-form/
MIT License
199 stars 17 forks source link

Duplicate forms *bug on iOS mobile #191

Open dxcore35 opened 8 months ago

dxcore35 commented 8 months ago

Describe the bug Very strange bug, on latest Obsidian app on iOS. It looks like after something is typed in first textfield, another overlaping same form is open, and all what was written is deleted. But somehow this window is still in background. Very difficult to explain.

To Reproduce

  1. Add this Template:
<%*

tp.file.rename(tp.date.now("[virtue-]YYMMDDhhmmss", 0));
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('Virtue');

tR +="subclass: " + result.asString('{{subclass}}') + "\n" + "area: " + result.asString('{{area}}') + "\n" + "aliases: " + result.asString('{{aliases}}') + "\n" + "element: " + result.asString('{{element}}')+ "\n" + "frequency: " + result.asString('{{frequency}}')+ "\n" + "summary: " + result.asString('{{summary}}')
%>

Trigger template from mobile

Additional context Please somebody try this on iPhone. I also have Obsidian sync there.

danielo515 commented 8 months ago

tp.file.rename is an asynchronous operation, but you are not awaiting it. My guess is that the form opens while the rename operation is in progress, and once it completes templater is called again with the newly created file. I think the rename operation can be creating a new file with the old content and then removing the old one, that may be the reason. Can you try to add a await in front of the rename and see if the problem still happens?

El dom, 31 dic 2023, 19:27, dxcore35 @.***> escribió:

Assigned #191 https://github.com/danielo515/obsidian-modal-form/issues/191 to @danielo515 https://github.com/danielo515.

— Reply to this email directly, view it on GitHub https://github.com/danielo515/obsidian-modal-form/issues/191#event-11362382514, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWOX5YEOZEWE3CHPOB3YMGU7LAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJRGM3DEMZYGI2TCNA . You are receiving this because you were assigned.Message ID: @.*** com>

dxcore35 commented 8 months ago

I added await there... but it is not this. I captured it here:

https://github.com/danielo515/obsidian-modal-form/assets/7279156/43cb7a7f-1a04-4fbb-ac23-d453afc3d6fe

danielo515 commented 8 months ago

What if you move the line to the last line of the file? I'm just guessing,since I don't have an iphone to test this.

On Mon, Jan 1, 2024 at 11:16 AM dxcore35 @.***> wrote:

I added await there... but it is not this. I captured it here:

https://github.com/danielo515/obsidian-modal-form/assets/7279156/43cb7a7f-1a04-4fbb-ac23-d453afc3d6fe

— Reply to this email directly, view it on GitHub https://github.com/danielo515/obsidian-modal-form/issues/191#issuecomment-1873260802, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWIG6HXLIPKF2HTW4K3YMKEIDAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZTGI3DAOBQGI . You are receiving this because you were mentioned.Message ID: @.***>

--

https://danielorodriguez.com

FelipeRearden commented 8 months ago

@dxcore35 and @danielo515

My attempt to help 🙏

IDEA 1: I would try to use await new Promise(r => setTimeout(r, 500)); after tp.file.rename(tp.date.now("[virtue-]YYMMDDhhmmss", 0));

<%*

await tp.file.rename(tp.date.now("[virtue-]YYMMDDhhmmss", 0));
await new Promise(r => setTimeout(r, 500));
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('Virtue');

tR +="subclass: " + result.asString('{{subclass}}') + "\n" + "area: " + result.asString('{{area}}') + "\n" + "aliases: " + result.asString('{{aliases}}') + "\n" + "element: " + result.asString('{{element}}')+ "\n" + "frequency: " + result.asString('{{frequency}}')+ "\n" + "summary: " + result.asString('{{summary}}')
%>

IDEA 2: before and after tp.file.rename(tp.date.now("[virtue-]YYMMDDhhmmss", 0));

<%*

await new Promise(r => setTimeout(r, 500));
await tp.file.rename(tp.date.now("[virtue-]YYMMDDhhmmss", 0));
await new Promise(r => setTimeout(r, 500));
const modalForm = app.plugins.plugins.modalforms.api;
const result = await modalForm.openForm('Virtue');

tR +="subclass: " + result.asString('{{subclass}}') + "\n" + "area: " + result.asString('{{area}}') + "\n" + "aliases: " + result.asString('{{aliases}}') + "\n" + "element: " + result.asString('{{element}}')+ "\n" + "frequency: " + result.asString('{{frequency}}')+ "\n" + "summary: " + result.asString('{{summary}}')
%>

Since you are creating a new file and renaming it just after the creation, MAYBE you need sometime WAIT time to run Modal Form

I hope it helps 🙏

dxcore35 commented 8 months ago

@FelipeRearden I added the await new Promise(r => setTimeout(r, 500)); Still it is doing this... I also forgot to mention that it will completely crash to Obsidian app!

https://github.com/danielo515/obsidian-modal-form/assets/7279156/11ea3dbc-f4a9-4eaa-a68d-5934f16b3938

FelipeRearden commented 8 months ago

I added the await new Promise(r => setTimeout(r, 500)); Still it is doing this... I also forgot to mention that it will completely crash to Obsidian app!

@dxcore35 I am sorry that me idea did not work. I really dont know what to say that could help.

But I wish you find a way to implement your workflow on Obsidian Mobile 🙏 I let you know if something triggers my mind that could be helpful 🙏

dxcore35 commented 8 months ago

@FelipeRearden Can you replicate this problem?

FelipeRearden commented 8 months ago

@FelipeRearden Can you replicate this problem?

I did not tried to replicate your issue on my end. I just stepped into the conversation because I run a lot of templater scripts on Obsidian Mobile on iPadOS and I was confident that I could help using this approach that I use all the time.

Again, I hope you can find a solution 🙏

dxcore35 commented 8 months ago

What if you move the line to the last line of the file? I'm just guessing,since I don't have an iphone to test this. On Mon, Jan 1, 2024 at 11:16 AM dxcore35 @.> wrote: I added await there... but it is not this. I captured it here: https://github.com/danielo515/obsidian-modal-form/assets/7279156/43cb7a7f-1a04-4fbb-ac23-d453afc3d6fe — Reply to this email directly, view it on GitHub <#191 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWIG6HXLIPKF2HTW4K3YMKEIDAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZTGI3DAOBQGI . You are receiving this because you were mentioned.Message ID: @.> -- --- https://danielorodriguez.com

@danielo515 Can you test it on android with Obsidian sync on and then off?

danielo515 commented 8 months ago

I don't have obsidian sync. I use syncthing and I never faced this problem before. Will try to reproduce in my Ipad whenever I can, I'm a bit busy this days

On Tue, Jan 9, 2024 at 11:13 AM Ahm @.***> wrote:

What if you move the line to the last line of the file? I'm just guessing,since I don't have an iphone to test this. … <#m-2111570424027561392> On Mon, Jan 1, 2024 at 11:16 AM dxcore35 @.> wrote: I added await there... but it is not this. I captured it here: https://github.com/danielo515/obsidian-modal-form/assets/7279156/43cb7a7f-1a04-4fbb-ac23-d453afc3d6fe https://github.com/danielo515/obsidian-modal-form/assets/7279156/43cb7a7f-1a04-4fbb-ac23-d453afc3d6fe — Reply to this email directly, view it on GitHub <#191 (comment) https://github.com/danielo515/obsidian-modal-form/issues/191#issuecomment-1873260802>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWIG6HXLIPKF2HTW4K3YMKEIDAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZTGI3DAOBQGI https://github.com/notifications/unsubscribe-auth/AARKJWIG6HXLIPKF2HTW4K3YMKEIDAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZTGI3DAOBQGI . You are receiving this because you were mentioned.Message ID: @.> -- --- https://danielorodriguez.com

@danielo515 https://github.com/danielo515 Can you test it on android with Obsidian sync on and then off?

— Reply to this email directly, view it on GitHub https://github.com/danielo515/obsidian-modal-form/issues/191#issuecomment-1882781457, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWJFNFC6U2WMONCETGTYNUJ6FAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBSG44DCNBVG4 . You are receiving this because you were mentioned.Message ID: @.***>

--

https://danielorodriguez.com

dxcore35 commented 4 months ago

@danielo515 Did you replicate that?

danielo515 commented 4 months ago

Nope. I don't have time now

El mié, 24 abr 2024, 16:01, Ahm @.***> escribió:

@danielo515 https://github.com/danielo515 Did you replicate that?

— Reply to this email directly, view it on GitHub https://github.com/danielo515/obsidian-modal-form/issues/191#issuecomment-2075025586, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARKJWK5CAM63S4K7CCON2LY663MNAVCNFSM6AAAAABBINIM6GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZVGAZDKNJYGY . You are receiving this because you were mentioned.Message ID: @.***>

hdsateyate commented 4 months ago

I have a similar problem in a QuickAdd capture with the code below.

The form appears as expected, I make my selection, click submit and then the form appears again and I have to repeat the process. The second time the process completes.

This happens on all of my devices, Macbook, Android, iPad.

Form template:

{
  "title": "Select time tracker category",
  "name": "time-tracker-form-categoryonly",
  "fields": [
    {
      "name": "category",
      "label": "Category",
      "description": "",
      "isRequired": false,
      "input": {
        "type": "dataview",
        "query": "dv.page(\"111 Root/2024_Time_Tracking.md\").tt_categories"
      }
    }
  ],
  "version": "1"
}

QuickAdd capture:

<%*
const modalForm = await app.plugins.plugins.modalforms.api;

const result = await modalForm.openForm("time-tracker-form-categoryonly");

const combined = result.get('category');
const categoryExtracted = combined.split("/")[0];
const tagExtracted = combined.split("/")[1];

%> <% categoryExtracted %>| <% tagExtracted %>|