[TWC] FormTiddlerPlugin, transcluded tiddler with <<formTiddler>> missing contents, revisited

98 views
Skip to first unread message

madscijr

unread,
Aug 11, 2015, 3:51:46 PM8/11/15
to tiddl...@googlegroups.com
I ran into the issue discussed here:

> popup of tiddler with <<formTiddler>> missing contents

where the fields in a form tiddler appear blank from within a transclusion.

Eric said the issue stems from the lookup function (story.findContainingTiddler) that the FormTiddlerPlugin uses to identify the tiddler in which the formTiddler and <data>...</data> block are stored, which always returns the title of the outermost containing tiddler. 
In the case of a transclusion this becomes the tiddler that invokes the <<tiddler>> macro rather than the actual source tiddler containing the form and data. 
As a workaround, Eric posted a modified config.macros.formTiddler.getContainingTiddlerName function with logic to find the transcluded tiddler. 
However, this breaks non-transcluded form tiddlers, and the thread doesn't go into any further fixes.

SO, I am wondering if we can enhance the logic of "FormTiddlerPluginTweak" to be able to tell whether the tiddler is in a transclusion or not,
and if it is, use Eric's new logic, else use the original logic...

To do this, I think we would just need a function "tiddlerIsNotTranscluded" that returns true if the tiddler is NOT inside a transclusion...

Any ideas how this can be done?

PS here are the tiddlers to recreate the problem, and the workaround plugin "FormTiddlerPluginTweak" (which is disabled - to see it in action, remove the systemConfigDisable tag).

PPS Also I am including the tiddlers you can import into your classic TiddlyWiki (2.6.1 or newer) - either save the attached file or save the HTML at the bottom and use the import plugin.

################################################################################################################################################################
Title:transcluded formTiddler missing contents test fix
Tags :tw test
Body :
+++(formTiddler-transclude-fix-test-1)[Edit Problem1|click to open][Hide Problem1|click to close]<<tiddler Problem1>>===<br>
+++(formTiddler-transclude-fix-test-2)[Edit Problem2|click to open][Hide Problem2|click to close]<<tiddler Problem2>>===<br>
+++(formTiddler-transclude-fix-test-3)[Edit Problem3|click to open][Hide Problem3|click to close]<<tiddler Problem3>>===<br>
################################################################################################################################################################
Title:Problem1
Tags :tw test
Body :
<<formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12>><data>{"notes":"This is some test content for Problem1."}</data>
################################################################################################################################################################
Title:Problem2
Tags :tw test
Body :
<<formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12>><data>{"notes":"This is some test content! (For Problem2.)"}</data>
################################################################################################################################################################
Title:Problem3
Tags :tw test
Body :
<<formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12>><data>{"notes":"Problem3 test content."}</data>
################################################################################################################################################################
Title:TextAreaTemplate010Rows080ColsWrapOffCourier12
Tags :FormTiddlerProject formTemplate
Body :
<html><TEXTAREA name="notes" rows="10" cols="80" WRAP="OFF" STYLE="font-size:12px; font-family: Courier;Courier New,Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,monospace;" ></TEXTAREA></html>
################################################################################################################################################################
Title:FormTiddlerPluginTweak
Tags :systemConfig systemConfigDisable
Body :
/*
FROM: https://groups.google.com/forum/m/#!topic/tiddlywiki/aon14ZtUGZ4

Subject: popup of tiddler with <<formTiddler>> missing contents

UPDATES FUNCTION IN FormTiddlerPlugin:
config.macros.formTiddler.getContainingTiddlerName = function(element) {
    return story.findContainingTiddler(element).id.substr(7);
}

5/23/09 Eric Shulman
> The slider isn't really the issue.  The problem is that data in a form
> tiddler does not appear in transclusion (e.g., when using the
> <<tiddler>> macro) - all you can see is the outline of the form, not
> the contents of the form fields.

The problem originates with the 'lookup function' that
[[FormTiddlerPlugin]] is using to identify the tiddler in which the
<<formTiddler>> macro and <data>...</data> block are stored (the
"source" tiddler).

Here's what that function currently looks like:
------------------------------------------
config.macros.formTiddler.getContainingTiddlerName = function(element)
{
        return story.findContainingTiddler(element).id.substr(7);
}
------------------------------------------

Unfortunately, story.findContainingTiddler() (a standard TW core
function) always returns the title of the *outermost* containing
tiddler -- in this case, the one that invokes the <<tiddler>> macro --
rather than name the actual source tiddler that was transcluded when
that macro was processed.  This, of course, produces the results that
you have observed: the plugin is unable to retrieve the form data,
because it is looking in the wrong tiddler!

Fortunately, there may be a relatively easy solution...

The key is to know that, whenever a tiddler is displayed in the story
column, it is contained within a 'wrapper' element that includes a
special "tiddler" attribute that holds the title of the current
tiddler.

Similarly, whenever a <<tiddler>> macro is processed, the transcluded
content is also contained in a wrapper element that has its own
"tiddler" attribute, set to the title of the source tiddler that was
transcluded.

The fix involves re-defining the FormTiddlerPlugin lookup function, so
that it will find the *innermost* wrapper that has a "tiddler"
attribute, and then use *that* value to retrieve the correct
<data>...</data> block.

We can do this by adding an extra tiddler, e.g.,
[[FormTiddlerPluginTweak]], tagged with 'systemConfig'
...
PLUS: as an added bonus, because 'transclusion' via the <<tabs>> macro
works the same way as the <<tiddler>> macro (i.e., it sets the
"tiddler" attribute of the containing wrapper), this 'tweak' should
also fix the same problem when using forms from within tabs!
------------------------------------------
the fix does work for viewing the form tiddler in the pop-up, but it
disables the viewing of the form tiddler in the straight "right from
the tiddler" way...
Any ideas? (he said hopefully :-)
------------------------------------------
This is really neat, especially because it's then possible to make
changes to a form while it's being viewed in transclusion!
But as Dave says, the refresh doesn't quite keep up - whenever either
the original tiddler or the transclusion tiddler is changed, the other
tiddler has to be closed and reopened in order to display the change.
Am I correct that the "wrapper" is also the reason why, even with this
tweak installed, my form <data> that is inside <part></part> still
doesn't display?
------------------------------------------
MadSciJr: so given the above, I am wondering if we can enhance the logic
to be able to tell whether the tiddler is in a transclusion or not,
and if it is, use Eric's new logic, else use the original logic...
To do this we need a function "tiddlerIsNotTranscluded" that returns true
if the tiddler is NOT inside a transclusion...

*/

// Internal.
//
// Returns the name of the tiddler containing the given element.
//
// Internal.
//
// Returns the name of the tiddler containing the given element.
//
config.macros.formTiddler.getContainingTiddlerName = function(e) {
//    if (tiddlerIsNotTranscluded(???))
//    {
//        // USE ORIGINAL LOGIC
//        return story.findContainingTiddler(element).id.substr(7);
//    }
//    else
//    {
//        // USE ENHANCED LOGIC:
        // find transcluded OR containing tiddler
        while(e &amp;&amp; !e.getAttribute(&quot;tiddler&quot;)) e=e.parentNode;
        return e?e.getAttribute(&quot;tiddler&quot;):e;
//    }
};
################################################################################################################################################################







5/23/09 Eric Shulman
> The slider isn't really the issue.  The problem is that data in a form
> tiddler does not appear in transclusion (e.g., when using the
> <<tiddler>> macro) - all you can see is the outline of the form, not
> the contents of the form fields.

The problem originates with the 'lookup function' that
[[FormTiddlerPlugin]] is using to identify the tiddler in which the
<<formTiddler>> macro and <data>...</data> block are stored (the
"source" tiddler).

Here's what that function currently looks like:
------------------------------------------
config.macros.formTiddler.getContainingTiddlerName = function(element)
{
        return story.findContainingTiddler(element).id.substr(7);
}
------------------------------------------

Unfortunately, story.findContainingTiddler() (a standard TW core
function) always returns the title of the *outermost* containing
tiddler -- in this case, the one that invokes the <<tiddler>> macro --
rather than name the actual source tiddler that was transcluded when
that macro was processed.  This, of course, produces the results that
you have observed: the plugin is unable to retrieve the form data,
because it is looking in the wrong tiddler!

Fortunately, there may be a relatively easy solution...

The key is to know that, whenever a tiddler is displayed in the story
column, it is contained within a 'wrapper' element that includes a
special "tiddler" attribute that holds the title of the current
tiddler.

Similarly, whenever a <<tiddler>> macro is processed, the transcluded
content is also contained in a wrapper element that has its own
"tiddler" attribute, set to the title of the source tiddler that was
transcluded.

The fix involves re-defining the FormTiddlerPlugin lookup function, so
that it will find the *innermost* wrapper that has a "tiddler"
attribute, and then use *that* value to retrieve the correct
<data>...</data> block.

We can do this by adding an extra tiddler, e.g.,
[[FormTiddlerPluginTweak]], tagged with 'systemConfig'
...
PLUS: as an added bonus, because 'transclusion' via the <<tabs>> macro
works the same way as the <<tiddler>> macro (i.e., it sets the
"tiddler" attribute of the containing wrapper), this 'tweak' should
also fix the same problem when using forms from within tabs!
------------------------------------------
the fix does work for viewing the form tiddler in the pop-up, but it
disables the viewing of the form tiddler in the straight "right from
the tiddler" way...
Any ideas? (he said hopefully :-)
------------------------------------------
This is really neat, especially because it's then possible to make
changes to a form while it's being viewed in transclusion!
But as Dave says, the refresh doesn't quite keep up - whenever either
the original tiddler or the transclusion tiddler is changed, the other
tiddler has to be closed and reopened in order to display the change.
Am I correct that the "wrapper" is also the reason why, even with this
tweak installed, my form <data> that is inside <part></part> still
doesn't display?
------------------------------------------
MadSciJr: so given the above, I am wondering if we can enhance the logic 
to be able to tell whether the tiddler is in a transclusion or not, 
and if it is, use Eric's new logic, else use the original logic...
To do this we need a function "tiddlerIsNotTranscluded" that returns true 
if the tiddler is NOT inside a transclusion...














<html><body><style type="text/css">    #storeArea {display:block;margin:1em;}    #storeArea div {padding:0.5em;margin:1em;border:2px solid black;height:10em;overflow:auto;}    #pureStoreHeading {width:100%;text-align:left;background-color:#eeeeee;padding:1em;}</style><div id="pureStoreHeading">    TiddlyWiki "PureStore" export file<br>    Source: <b>file:///C:/Temp/TiddlyWiki_2.6.1.html</b><br>    Title: <b>My TiddlyWiki</b><br>    Subtitle: <b>a reusable non-linear personal web notebook</b><br>    Created: <b>8/11/2015, 3:02:21 PM</b> by <b>madscijr</b><br>    TiddlyWiki 2.6.1 / ExportTiddlersPlugin 2.8.4<br>    Notes:<hr><pre></pre></div><div id="storeArea">TextAreaTemplate010Rows080ColsWrapOffCourier12
<div title="TextAreaTemplate010Rows080ColsWrapOffCourier12" creator="madscijr" modifier="madscijr" created="201507092031" modified="201508111900" tags="FormTiddlerProject formTemplate" changecount="8" alias="[[TextAreaTemplate10Rows080ColsWrapOffCourier12]] [[TextAreaTemplate10Rows80ColsWrapOffCourier12]]">
<pre>&lt;html&gt;&lt;TEXTAREA name=&quot;notes&quot; rows=&quot;10&quot; cols=&quot;80&quot; WRAP=&quot;OFF&quot; STYLE=&quot;font-size:12px; font-family: Courier;Courier New,Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,monospace;&quot; &gt;&lt;/TEXTAREA&gt;&lt;/html&gt;</pre>
</div>
FormTiddlerPluginTweak
<div title="FormTiddlerPluginTweak" modifier="madscijr" created="201508111812" modified="201508111851" tags="systemConfig systemConfigDisable" changecount="3" alias="">
<pre>/*
UPDATES FUNCTION IN FormTiddlerPlugin:
config.macros.formTiddler.getContainingTiddlerName = function(element) {
    return story.findContainingTiddler(element).id.substr(7);
}

5/23/09 Eric Shulman
&gt; The slider isn't really the issue.  The problem is that data in a form
&gt; tiddler does not appear in transclusion (e.g., when using the
&gt; &lt;&lt;tiddler&gt;&gt; macro) - all you can see is the outline of the form, not
&gt; the contents of the form fields.

The problem originates with the 'lookup function' that
[[FormTiddlerPlugin]] is using to identify the tiddler in which the
&lt;&lt;formTiddler&gt;&gt; macro and &lt;data&gt;...&lt;/data&gt; block are stored (the
&quot;source&quot; tiddler).

Here's what that function currently looks like:
------------------------------------------
config.macros.formTiddler.getContainingTiddlerName = function(element)
{
        return story.findContainingTiddler(element).id.substr(7);
}
------------------------------------------

Unfortunately, story.findContainingTiddler() (a standard TW core
function) always returns the title of the *outermost* containing
tiddler -- in this case, the one that invokes the &lt;&lt;tiddler&gt;&gt; macro --
rather than name the actual source tiddler that was transcluded when
that macro was processed.  This, of course, produces the results that
you have observed: the plugin is unable to retrieve the form data,
because it is looking in the wrong tiddler!

Fortunately, there may be a relatively easy solution...

The key is to know that, whenever a tiddler is displayed in the story
column, it is contained within a 'wrapper' element that includes a
special &quot;tiddler&quot; attribute that holds the title of the current
tiddler.

Similarly, whenever a &lt;&lt;tiddler&gt;&gt; macro is processed, the transcluded
content is also contained in a wrapper element that has its own
&quot;tiddler&quot; attribute, set to the title of the source tiddler that was
transcluded.

The fix involves re-defining the FormTiddlerPlugin lookup function, so
that it will find the *innermost* wrapper that has a &quot;tiddler&quot;
attribute, and then use *that* value to retrieve the correct
&lt;data&gt;...&lt;/data&gt; block.

We can do this by adding an extra tiddler, e.g.,
[[FormTiddlerPluginTweak]], tagged with 'systemConfig'
...
PLUS: as an added bonus, because 'transclusion' via the &lt;&lt;tabs&gt;&gt; macro
works the same way as the &lt;&lt;tiddler&gt;&gt; macro (i.e., it sets the
&quot;tiddler&quot; attribute of the containing wrapper), this 'tweak' should
also fix the same problem when using forms from within tabs!
------------------------------------------
the fix does work for viewing the form tiddler in the pop-up, but it
disables the viewing of the form tiddler in the straight &quot;right from
the tiddler&quot; way...
Any ideas? (he said hopefully :-)
------------------------------------------
This is really neat, especially because it's then possible to make
changes to a form while it's being viewed in transclusion!
But as Dave says, the refresh doesn't quite keep up - whenever either
the original tiddler or the transclusion tiddler is changed, the other
tiddler has to be closed and reopened in order to display the change.
Am I correct that the &quot;wrapper&quot; is also the reason why, even with this
tweak installed, my form &lt;data&gt; that is inside &lt;part&gt;&lt;/part&gt; still
doesn't display?
------------------------------------------
MadSciJr: so given the above, I am wondering if we can enhance the logic
to be able to tell whether the tiddler is in a transclusion or not,
and if it is, use Eric's new logic, else use the original logic...
To do this we need a function "tiddlerIsNotTranscluded" that returns true
if the tiddler is NOT inside a transclusion...
*/

// Internal.
//
// Returns the name of the tiddler containing the given element.
//
config.macros.formTiddler.getContainingTiddlerName = function(e) {
//    if (tiddlerIsNotTranscluded(???))
//    {
//        // USE ORIGINAL LOGIC
//        return story.findContainingTiddler(element).id.substr(7);
//    }
//    else
//    {
//        // USE ENHANCED LOGIC:
        // find transcluded OR containing tiddler
        while(e &amp;&amp; !e.getAttribute(&quot;tiddler&quot;)) e=e.parentNode;
        return e?e.getAttribute(&quot;tiddler&quot;):e;
//    }
};
/*
FROM:
popup of tiddler with &lt;&lt;formTiddler&gt;&gt; missing contents
https://groups.google.com/forum/m/#!topic/tiddlywiki/aon14ZtUGZ4

5/22/09 Dave
Hi,

I have a tiddler with a nested slider popup like this

+++^* &lt;&lt;tiddler Problem1&gt;&gt; ===


and the tiddler called &quot;Problem1&quot; has this in it:

&lt;&lt;formTiddler ProblemTemplate&gt;&gt;&lt;data&gt;{&quot;location&quot;:&quot;sdfgsdfg&quot;,&quot;referral
to&quot;:&quot;elbow&quot;,&quot;course&quot;:&quot;better&quot;}&lt;/data&gt;

When I click the slider to show the pop-up, the little box around the
pop-up only borders part of the tiddler, and the field boxes extend
beyond the right border and are empty.  When I open the tiddler
normally it is fine.


Any ideas?

Thanks,
DP
5/22/09 Eric Shulman
&gt; +++^* &lt;&lt;tiddler Problem1&gt;&gt; ===
&gt; When I click the slider to show the pop-up, the little box around the
&gt; pop-up only borders part of the tiddler, and the field boxes extend
&gt; beyond the right border and are empty.  When I open the tiddler
&gt; normally it is fine.

Try specifying a fixed width for the floating slider panel:

+++^40em^* &lt;&lt;tiddler Problem1&gt;&gt; ===

-e

5/22/09 cmari
The slider isn't really the issue.  The problem is that data in a form
tiddler does not appear in transclusion (e.g., when using the
&lt;&lt;tiddler&gt;&gt; macro) - all you can see is the outline of the form, not
the contents of the form fields.  The only way I've been able to make
the &lt;&lt;tiddler&gt;&gt; macro display the contents of forms is by adding
another macro inside the form tiddler like &lt;&lt;showData&gt;&gt; or a fET macro
that calls up the data and puts it into a table (inside the form
tiddler itself, so that the data is effectively displayed twice in
that tiddler - though it can be hidden in a slider).  I'd be
interested to hear about other solutions!
cmari
- show quoted text -
5/23/09 Eric Shulman
&gt; The slider isn't really the issue.  The problem is that data in a form
&gt; tiddler does not appear in transclusion (e.g., when using the
&gt; &lt;&lt;tiddler&gt;&gt; macro) - all you can see is the outline of the form, not
&gt; the contents of the form fields.

The problem originates with the 'lookup function' that
[[FormTiddlerPlugin]] is using to identify the tiddler in which the
&lt;&lt;formTiddler&gt;&gt; macro and &lt;data&gt;...&lt;/data&gt; block are stored (the
&quot;source&quot; tiddler).

Here's what that function currently looks like:
------------------------------------------
config.macros.formTiddler.getContainingTiddlerName = function(element)
{
        return story.findContainingTiddler(element).id.substr(7);
}
------------------------------------------

Unfortunately, story.findContainingTiddler() (a standard TW core
function) always returns the title of the *outermost* containing
tiddler -- in this case, the one that invokes the &lt;&lt;tiddler&gt;&gt; macro --
rather than name the actual source tiddler that was transcluded when
that macro was processed.  This, of course, produces the results that
you have observed: the plugin is unable to retrieve the form data,
because it is looking in the wrong tiddler!

Fortunately, there may be a relatively easy solution...

The key is to know that, whenever a tiddler is displayed in the story
column, it is contained within a 'wrapper' element that includes a
special &quot;tiddler&quot; attribute that holds the title of the current
tiddler.

Similarly, whenever a &lt;&lt;tiddler&gt;&gt; macro is processed, the transcluded
content is also contained in a wrapper element that has its own
&quot;tiddler&quot; attribute, set to the title of the source tiddler that was
transcluded.

The fix involves re-defining the FormTiddlerPlugin lookup function, so
that it will find the *innermost* wrapper that has a &quot;tiddler&quot;
attribute, and then use *that* value to retrieve the correct
&lt;data&gt;...&lt;/data&gt; block.

We can do this by adding an extra tiddler, e.g.,
[[FormTiddlerPluginTweak]], tagged with 'systemConfig', with the
following replacement code:
------------------------------------------
config.macros.formTiddler.getContainingTiddlerName = function(e) {
        // find transcluded OR containing tiddler
        while(e &amp;&amp; !e.getAttribute(&quot;tiddler&quot;)) e=e.parentNode;
        return e?e.getAttribute(&quot;tiddler&quot;):e;
};
------------------------------------------

PLUS: as an added bonus, because 'transclusion' via the &lt;&lt;tabs&gt;&gt; macro
works the same way as the &lt;&lt;tiddler&gt;&gt; macro (i.e., it sets the
&quot;tiddler&quot; attribute of the containing wrapper), this 'tweak' should
also fix the same problem when using forms from within tabs!

Give it a try and let me know what happens...

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
5/23/09 Dave
I think you're on to something...

the fix does work for viewing the form tiddler in the pop-up, but it
disables the viewing of the form tiddler in the straight &quot;right from
the tiddler&quot; way...

Any ideas? (he said hopefully :-)

Thanks,
Dave
- show quoted text -
5/23/09 cmari
This is really neat, especially because it's then possible to make
changes to a form while it's being viewed in transclusion!
But as Dave says, the refresh doesn't quite keep up - whenever either
the original tiddler or the transclusion tiddler is changed, the other
tiddler has to be closed and reopened in order to display the change.

Am I correct that the &quot;wrapper&quot; is also the reason why, even with this
tweak installed, my form &lt;data&gt; that is inside &lt;part&gt;&lt;/part&gt; still
doesn't display?
cmari
- show quoted text -
5/27/09 Dave
Okay, I've tried something different to try to get this idea to work:
I was wondering if I could do the same thing with custom fields
instead of FormTiddler data, so I learned how to use custom fields and
&quot;hide when&quot;.  Unfortunately I forgot that the custom fields don't
display inside the main tiddler body.  Is there a way to get a custom
field to show up with a &lt;&lt;tiddler TiddlerName&gt;&gt;?

Dave
- show quoted text -
&gt; &gt; &gt; TiddlyTools / ELS Design Studios- Hide quoted text -
&gt;
&gt; - Show quoted text -
*/
</pre>
</div>
transcluded formTiddler missing contents test fix
<div title="transcluded formTiddler missing contents test fix" modifier="madscijr" created="201508111800" modified="201508111840" tags="tw test" changecount="9" alias="">
<pre>+++(formTiddler-transclude-fix-test-1)[Edit Problem1|click to open][Hide Problem1|click to close]&lt;&lt;tiddler Problem1&gt;&gt;===&lt;br&gt;
+++(formTiddler-transclude-fix-test-2)[Edit Problem2|click to open][Hide Problem2|click to close]&lt;&lt;tiddler Problem2&gt;&gt;===&lt;br&gt;
+++(formTiddler-transclude-fix-test-3)[Edit Problem3|click to open][Hide Problem3|click to close]&lt;&lt;tiddler Problem3&gt;&gt;===&lt;br&gt;
</pre>
</div>
Problem3
<div title="Problem3" creator="madscijr" modifier="madscijr" created="201508111803" modified="201508111803" tags="tw test" changecount="1" alias="">
<pre>&lt;&lt;formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12&gt;&gt;&lt;data&gt;{&quot;notes&quot;:&quot;Problem3 test content.&quot;}&lt;/data&gt;</pre>
</div>
Problem2
<div title="Problem2" creator="madscijr" modifier="madscijr" created="201508111802" modified="201508111803" tags="tw test" changecount="1" alias="">
<pre>&lt;&lt;formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12&gt;&gt;&lt;data&gt;{&quot;notes&quot;:&quot;This is some test content! (For Problem2.)&quot;}&lt;/data&gt;</pre>
</div>
Problem1
<div title="Problem1" modifier="madscijr" created="201508111802" modified="201508111802" tags="tw test" changecount="1" alias="">
<pre>&lt;&lt;formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12&gt;&gt;&lt;data&gt;{&quot;notes&quot;:&quot;This is some test content for Problem1.&quot;}&lt;/data&gt;</pre>
</div></div><!--POST-BODY-START-->
<!--POST-BODY-END--></body></html>



TWC_transcluded_formTiddler_issue.html

madscijr

unread,
Aug 12, 2015, 4:48:31 PM8/12/15
to TiddlyWiki
I tried messing around with the "FormTiddlerPluginTweak" plugin logic, and sort of got it working.  See attached file for the modified tiddler code (title "FormTiddlerPluginTweak", tag "systemConfig"), it's also included below in this post (along with test tiddlers and form template).

Now you can open a formTiddler and it displays data transcluded or not.

HOWEVER, if you have a form tiddler open at the same time as the transcluded form tiddler, and then edit the non-transcluded form tiddler's markup, when you exit out of edit mode, the form displays blank!  But if you close the transcluded version, then edit the non-transcluded verison, when you exit edit mode the form again displays data.

I suspect that either
1. "config.macros.formTiddler.getContainingTiddlerName" needs some logic to determine if the tiddler is transcluded when another tiddler that references the same form and data is also open, or
2. some other function(s) or method(s) are involved that need to be similarly modified

Any ideas?

Below are the steps to reproduce, followed by the modified plugin and test tiddlers...

Any help appreciated!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Here are steps to reproduce the strange behavior.

Note: save a copy of your TiddlyWiki to "C:\Temp\TiddlyWiki_2.6.1.html" or else adjust the file path below to match what you are using...

Test 1:
Open in browser: file:///C:/Temp/TiddlyWiki_2.6.1.html
Open tiddler "Problem1". Tiddler displays data in form.
Edit tiddler "Problem1". Press ESC to cancel edit. Tiddler still displays data in form.
Leaving "Problem1" open, open "Problem1 (transcluded)". Tiddler displays data in form.
Edit tiddler. Press ESC to cancel edit. Form still displays data.
Edit tiddler "Problem1" again. Press ESC to cancel edit. Tiddler no longer displays any data in form. ???
Close tiddler "Problem1 (transcluded)".
Edit tiddler "Problem1". Press ESC to cancel edit. Tiddler once again displays data in form.
Close all tiddlers.
Open tiddler "Problem1". Tiddler displays data in form.
Leaving "Problem1" open, open "Problem1 (transcluded)". Tiddler displays data in form.

Test 2:
Open in browser: file:///C:/Temp/TiddlyWiki_2.6.1.html#[[Problem1%20%28transcluded%29]]%20Problem1
Tiddler "Problem1 (transcluded)" displays data in form.
Tiddler "Problem1" does not display data in form.
Close tiddler "Problem1 (transcluded)".
Edit tiddler "Problem1". Press ESC to cancel edit. Tiddler once again displays data in form.

Test 3:
Open in browser: file:///C:/Temp/TiddlyWiki_2.6.1.html#Problem1
Tiddler "Problem1" displays data in form.
Edit tiddler. Press ESC to cancel edit. Form still displays data.
Leaving "Problem1" open, open "Problem1 (transcluded)". Tiddler displays data in form.
Edit tiddler "Problem1" again. Press ESC to cancel edit. Tiddler no longer displays any data in form. ???

Test 4:
Open in browser: file:///C:/Temp/TiddlyWiki_2.6.1.html#[[Problem1%20%28transcluded%29]]
Tiddler "Problem1 (transcluded)" displays data in form.
Edit tiddler. Press ESC to cancel edit. Form still displays data.


The test tiddlers and the new version of the plugin:


################################################################################################################################################################
Title:TextAreaTemplate010Rows080ColsWrapOffCourier12
Tags :FormTiddlerProject formTemplate
Text :<html><TEXTAREA name="notes" rows="10" cols="80" WRAP="OFF" STYLE="font-size:12px; font-family: Courier;Courier New,Consolas,Monaco,Lucida Console,Liberation Mono,DejaVu Sans Mono,Bitstream Vera Sans Mono,monospace;" ></TEXTAREA></html>
################################################################################################################################################################
Title:Problem1
Tags :test
Text :<<formTiddler TextAreaTemplate010Rows080ColsWrapOffCourier12>><data>{"notes":"This is some test content for Problem1."}</data>
################################################################################################################################################################
Title:Problem1 (transcluded)
Tags :test
Text :<<tiddler Problem1>>

################################################################################################################################################################
Title:FormTiddlerPluginTweak
Tags :systemConfig
Text :
///////////////////////////////////////////////////////////////////////////////
/*
Internal.

Infernal, too!  I'm sure my JavaScript is atrocious... I don't care, as long as it works.  (which it doesn't, doh)
It's 2015, by now we should have tools smart enough to re-render code to your liking,
whatever paradigm you understand or your brain works best with, whatever syntax you prefer, etc.
Syntax should serve the programmer, whatever makes it easy for them.
Readability is more important than performance.  Programmer time is more valuable than machine time.
And who cares anyway, it's a friggin TiddlyWiki!


Returns the name of the tiddler containing the given element.
Checks to see if the tiddler is transcluded in another tiddler,
and if it is, don't return the containing tiddler by mistake.
*/
config.macros.formTiddler.getContainingTiddlerName = function(oElement)
{
   
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Local utility function
    function tryGetString(myValue)
    {
        var result = "";
        try
        {
            result = myValue.toString();
        } // try
        catch(e)
        {
            result = "";
        } // catch
        return result;
    } // tryGetString
   
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Return how many levels down the given tiddler is.
    // More than 1 means it is transcluded inside another tiddler (I think?)
    function countParents(obj)
    {
        var result = 0;
        var oParent = null;
        try
        {
            if (obj)
            {
                if (!obj.getAttribute("tiddler"))
                {
                    result += 1;
                    try
                    {
                        oParent = obj.parentNode;
                    } // try
                    catch(e2)
                    {
//alert("ERROR IN countParents, retrieving obj.parentNode: " + e2.message + "");
                        oParent = null;
                    } // catch
                    if (oParent !== null)
                    {
//alert("counting parents... result=" + tryGetString(result) + "");
                        result += countParents(oParent);
                    } // if
                } // if
            } // if
        } // try
        catch(e1)
        {
//alert("ERROR IN countParents: " + e1.message + "");
            result = 0;
        } // catch
        return result;
    } // countParents
   
    // =============================================================================
    // Main logic
    try
    {
        var iCount = 0;
        var bIsTranscluded = false;
       
        // -----------------------------------------------------------------------------
        // DETERMINE IF TIDDLER IS TRANSCLUDED
        iCount = countParents(oElement);
       
        //bIsTranscluded = (iCount > 0);
        bIsTranscluded = (iCount < 1);
       
        // -----------------------------------------------------------------------------

        // find transcluded OR containing tiddler
        if (bIsTranscluded)
        {
            // USE ERIC'S NEW LOGIC
            while (oElement && !oElement.getAttribute("tiddler"))
            {
                oElement = oElement.parentNode;
            } // while
            return oElement ? oElement.getAttribute("tiddler"):oElement;
        } // if
        else
        {
            // USE THE ORIGINAL LOGIC
            return story.findContainingTiddler(oElement).id.substr(7);
        } // else
    } // try
    catch(e3)
    {
        alert("" +
            "ERROR IN FormTiddlerPluginTweak plugin, \n" +
            "function config.macros.formTiddler.getContainingTiddlerName: \n" +
            e3.message +
            "");
    } // catch
}; // getContainingTiddlerName
################################################################################################################################################################

FormTiddlerPluginTweak (ver 2-01-05).js
Reply all
Reply to author
Forward
0 new messages