Hi, First personally I would love for challenges like these to become a thing since not only do I get to learn things I normally would not necessarily need for myself and second I think it would be interesting to see different approaches to the same challenge.
Second here is my solution for the basic challenge:
*How the macro works:*
- The Macro is still called with tiddlername and fieldname with the same
defaults.
- The outermost list widgets check if currentValue is empty or not and
react accordingly
- If there is no currentValue the first select will be created with all
values currently defined in the corresponding config tiddler.
- The config tiddler to use is defined in the configTiddler variable
to make it easier to change the tiddler. Currently the only hard coded
part
is that the pairs have to be in the text field.
- If there is a currentValue - or a value was chosen in the first select
- then the second select will be created only showing the corresponding
pair. E.g.: If the current value is 'yes' only the options 'yes' and 'no'
are available.
- For now the value pair has to be defined in the config tiddler for
this to work. In the version for the extended challenge I hopefully
manage
to have a way to create a field on setting the initial value that will
keep
the respective pair within the tiddler itself.
*How to extend the macro*
- Simply add another pair/set of options to the config separated at
least by ';' for the pair and by at least one space for each option.
- Only caveat for now is each value in a pair/set has to be a single
word/string without spaces.
*Macro*
\define smart-configure(tiddlername fieldname:"fieldname")
<$set name=configTiddler value="$:/smartConfig/config/pairs">
<$set name=tiddlername value="$tiddlername$" emptyValue=<<currentTiddler>> >
<$set name=currentValue value={{{ [<tiddlername>get[$fieldname$]trim[]] }}}>
tiddlername=<<tiddlername>>, fieldname=$fieldname$, currentValue=<<
currentValue>><br>
<$list filter="[<currentValue>is[blank]]" variable=nul>
Select initial value:
<$select tiddler=<<tiddlername>> field="$fieldname$" default=<<currentValue
>> >
<$list filter='[<configTiddler>get[text]split[;]!is[blank]join[ ]]'>
<$list filter="[<currentTiddler>split[ ]!is[blank]]">
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$list>
</$select>
</$list>
<$list filter="[<currentValue>!is[blank]]" variable=nul>
<$list filter="[<configTiddler>get[text]split[;]trim[]!is[blank]]
+[search<currentValue>]">
<$select tiddler=<<tiddlername>> field="$fieldname$" default=<<currentValue
>> >
<$list filter="[<currentTiddler>split[ ]]">
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>
</$list>
</$list>
</$set>
</$set>
</$set>
\end
*Configuration*
yes no; show hide; true false; left right; top bottom
The attached version of the macro tiddler includes a text edit widget to
quickly edit the config tiddler and two examples to see both states of the
macro.
The import and tiddlers work on empty.html, tiddlywiki.com and the
playground <https://anthonymuscio.github.io/playground.html>.
For now I will leave it at that, but will look into the extended challenge
within the next days since it has some very interesting points to solve.
Regards,
Felicia
--
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/tiddlywiki/62e98c22-5f24-4388-b780-34728f26c76co%40googlegroups.com.
SmartConfigure.json
Description: application/json

