Replace certain values in list field using edit text and action widgets

The title doesn’t convey the complexity of the question appropriately. But I was not sure how to frame the title.
So I have this need in my dynamic table.
I have fields like field-1, field-2, field-3 and so on with certain field-values like fieldvalue-1, fieldvalue-2, fieldvalue-3 and so on.
Again I store these field-values in a list like field called tbl-fields-value as fieldvalue-1 fieldvalue-2 fieldvalue-3

I can edit the field-values of the fields like field-1, field-2, field-3using edit-text widget. Whenever a field-value change, for example say fieldvalue-1 of the field-1 change, I want that value to change in the list field called tbl-fields-value also. Is that possible ?

This image show how I am editing the fields like field-1. Its based on a similar solution provided by @EricShulman in an old post of mine. On pressing the edit text widget, a pop up opens using reveal widget which shows a list of values as button widgets. Actions parameter of these button widgets can be used to edit the value of the list like field called tbl-fields-value
I tried search replace operator, but the result was not accurate. So can someone help to solve this.

This was my attempt

\function loading-tbl-field-name()
[<currentTiddler>get<tbl-field-select>]
\end loading-tbl-field-name

\function tbl-field-names()
[enlist<select-field>search:title<loading-tbl-field-name>format:titlelist[]join[ ]]
\end tbl-field-names

\function tbl-field-name-popid()
[[$:/state/tbl-field-name-pop/]addsuffix{!!title}addsuffix[/]addsuffix<tbl-field-select>]
\end tbl-field-name-popid

\procedure tbl-field-name-pop-action()
<$action-setfield $tiddler=<<currentTiddler>>  $field=<<tbl-field-select>> $value=<<tbl-field-name>> /> 
<$list filter="[<currentTiddler>fields[]prefix[field-]]" variable="tbl-field-select">
<$let tbl-field-select-value={{{ [<currentTiddler>get<tbl-field-select>] }}}
>
<$action-setfield $tiddler=<<currentTiddler>>  $field="tbl-fields-value"  $value={{{ [{!!tbl-fields-value}search-replace<tbl-field-select-value>,<tbl-field-name>] }}} />
</$let>
</$list>
\end tbl-field-name-pop-action

<$let 
tbl-field-selector={{!!tbl-field-selector-value}}
select-field={{{ [<tbl-field-selector>get[list]sort[]] }}} 
tbl-filter={{{ [<currentTiddler>get[tbl-filter-value]] ~[<tbl_filter>] }}}
tbl-fields={{{ [<currentTiddler>get[tbl-fields-value]] ~[<tbl_fields>] }}}
>

<$list filter="[<currentTiddler>fields[]prefix[field-]]" variable="tbl-field-select"><$edit-text tiddler=<<currentTiddler>> field=<<tbl-field-select>> tag="input" class="column-selector tc-popup-handle tc-max-width" focusPopup=<<tbl-field-name-popid>>/>
<$reveal type="popup" state=<<tbl-field-name-popid>> class="tc-drop-down" position="below" animate="yes" retain="yes" style="min-width:auto;">   
   <$list filter=<<tbl-field-names>> variable="tbl-field-name">
      <$button class="tc-btn-invisible" actions=<<tbl-field-name-pop-action>> >
         <div style="overflow:₹;text-overflow:ellipsis;">
         <$text text=<<tbl-field-name>>/>
         </div>
      </$button>
</$list>
</$reveal>
</$list>
</$let>

Try replacing this line:

<$action-setfield $tiddler=<<currentTiddler>>  $field="tbl-fields-value"  $value={{{ [{!!tbl-fields-value}search-replace<tbl-field-select-value>,<tbl-field-name>] }}} />

with these lines:

<$list filter="[<currentTiddler>contains:tbl-fields-value<tbl-field-select-value>]" variable=none>
<$action-listops $field="tbl-fields-value" $subfilter="[<tbl-field-name>] +[replace<tbl-field-select-value>]"/>
</$list>

Notes:

  • The enclosing $list widget ensures that the tbl-fields-value list field currently contains the tbl-field-select-value
  • The $action-listops widget updates the tbl-fields-value list field by replacing the tbl-field-select-value list item with the tbl-field-name value
  • Note there is no need to specify $tiddler=<<currentTiddler>>, as that is the default target tiddler for $action-listops
1 Like

It was replacing not correctly… I have created a demo tiddler here…My TiddlyWiki — a non-linear personal web notebook

I don’t want to entirely replace the list field…i only want to replcae the one particular edited fieldvalue at a time

Re-read what I wrote…

$action-listops does NOT replace the entire list field… it only replaces a list ITEM within the field.

See https://tiddlywiki.com/#replace%20Operator%20(Examples)

-e

@EricShulman I read the docs…but still my code doesn’t replace correctly…can you take a look at the code …I will try to solve this from side also.

Can we just step back for a minute to understand your purpose here?

It seems to me that you want a list of the values in certain fields…

Why not just generate/use that list dynamically (based in real time on what the values are), rather than doubling your storage and maintenance burden by having an additional field that needs to be updated whenever a value changes elsewhere?

This was actually for my dynamic table shown here - My TiddlyWiki — a non-linear personal web notebook

Actually I solved the issue by adding a plus button next to the edit text widget to add the field-value to a config tiddler before changing the field value. Code given by Eric was not working since the field-value doesn’t exist when I try to edit it using edit text widget.

The context behind double storage is little tough to explain. During the initial development of this dynamic table, i was using fields to manipulate or customize the table. Now I am adding support for procedure parameter for the same purpose. That’s why I have to do this double work of saving data in fields. May be in the future as I refine the code I can avoid such double storage.

This has been a long journey behind the development of this dynamic table procedure. Its almost reaching a final stage. I am soo happy that finally I have my own dynamic table which I can customize as I wish.

Yes, I think you should look into avoiding double-storage if you can.

You can make a template for any column in Shiraz dynamic tables. In all of the examples given by @Mohammad, the columns (beyond tbl-expand, tbl-clone, etc.) are fieldnames, and the templates just determine how the field content is formatted. But I have columns that represent all sorts of computed content, such as totals, filtered lists, etc.

I think alongside the “philosophy of tiddlers” (suggesting that one tiddler should represent whatever the most atomic “unit” is that you functionally interact with), we should usually see “fields” as representing some one dimension of that thing or concept (and, in my case, a field name and many values that show up in fields, also become tiddlers or tiddler-like nodes).

Anytime an input in one place seems to “require” a routine input in another, of course you can build a solution that accomplishes that task, but you probably are missing the power of tiddlywiki to work dynamically with the information you have, each bit in its proper place.

2 Likes

That’s right. Storing the same values in several different places will immediately cause a consistency problem. That means your values need to be in sync. If they are not, you have a problem. So you should refine your code as soon as possible.

The problem is that I use separate fields for each column headers in my dynamic table. Column headers are actually edit text widget of the corresponding fields. I can and want to change the column headers directly from the view mode using these edit text widgets. For that I need separate fields for each column headers.

Here comes the problem. I also want to assign column headers using procedure parameters. For this I am also storing all the column headers in a list like fields. Because of this double storage, whenever I am changing the column header using edit text widget, corresponding change should happen in the list field. I was able to keep the changes in sync using an extra button placed next to the edit text widget in the column header which saves the current column header field-name into a config tiddler. It just works ok now.

If I have to avoid the double storage, there should be a way to edit each field-values in a list field separately. I am not aware of any such option currently. Can some one suggest a way to edit each field-value in the list field individually ?

In itself this is not a problem (if I understand your meaning): usually each column header does correspond to a field… Do you mean: your <storyTiddler> has multiple fields, and the dynamic tables looks at this and that field (in <storyTiddler>) to determine which fields should appear in the table?

I do something similar, but it’s just a LIST of fields to include in a dynamic table, so that I can modify, on the fly, which columns to display… But then my edit-text widget (for the list of field/columns to show) lives not in the table, but in the host tiddler… (And something like radio buttons or checkboxes can help adjust the list of dynamic-table fields in an easy way.)

I’m guessing you have something like roles for field-names. So there’s a field where you’re storing WHICH field-names should appear as columns in this dynamic table, yes?

The phrase

… is not clear (edit “of” the fields means… what?) You might mean…

  • edit widget to change the name of the field itself? (But renaming actual fields in remote tiddlers wouldn’t be done in the header of a dynamic table…)
  • edit widget to change the field values for the table’s tiddlers (But values for the specific “records” that correspond to each tiddler row surely wouldn’t be changed in the header…)
  • edit widget changes the value for a field here in <storyTiddler>, designed to hold the name of the target field (whose contents should appear in the body of the dynamic-table column). Is that right?

Only the third of these begins to make sense to me. Even so, I’m not sure why/how you’re seeing a need for an extra step to create/modify a list whenever you edit that info (which is — again, if I follow! — a field name to serve as <currentColumn>, edited and stored within a field of <storyTiddler>)

My sense is that you may have a more convoluted solution than you need. But I admit that minor language challenges may be interfering with the clarity of our conversation…

Ahh… Maybe you want to learn more about Listops? https://tiddlywiki.com/#Listops%20Operators

Specifically, the replace operator may be what you’re looking for.

One further thought: the “fields” parameter in your dynamic-table instance can accept a complex filter. That may be the way to get around thinking you need to maintain a list, in addition to the basic place where the list values primarily live.

For example:

fields:"tbl-expand [{!!priority_field}] title [{!!custom_field}enlist-input[]] [{!!select_fields}enlist-input[]]"  

Here’s a demo of what we could call “dynamic dynamic table” :wink: :

I have not tried to make the column-headers into edit widgets, though I did put some such widgets into the caption area. I suppose it’s possible to make the dynamic table headers function this way, but that would be a complex UI preference that seems less central to your basic needs, if I understand correctly.

Check this demo wiki which was linked in one of my previous post…I will explain more once I am back home

You may have a closer look at the ActionListOps-Widget and the examples.

You will need to play a bit with the examples yourself, to see how it all works. It’s a bit complex, but it should do what you need.