Predefined list in field?

Hello everyone.

I am making a template to enter kitchen recipes in a standardized way, so that they all have the same format.
To enter certain information I use fields so that later I can reuse said information. I would like to know if a predefined list can be used to enter certain values in a field.

For example: in the field of types of cuisine I can choose between: Mexican Spanish Italian Chinese. So that you do not have to go around remembering the correct values and avoid writing errors as much as possible.

I’ve been looking but can’t find anything like it. Can you tell me if it can be done easily and if you know of any examples?

Thank you very much.

1 Like

Use the $select widget, like this:

<$select field="cuisine">
   <option>Mexican</option>
   <option>Spanish</option>
   <option>Italian</option>
   <option>Chinese</option>
</$select>

ref: https://tiddlywiki.com/#SelectWidget

enjoy,
-e

1 Like

Your thread title reads “predefined list in field” so, riffing off Erics solution, here’s another one:

Create a field
cuisine-options: Mexican Chinese ...

then, in the text:

<$select field="cuisine">
<$list filter='[{!!cuisine-options}enlist-input[]]'>
   <option>{{!!title}}</option>
</$list>
</$select>

The selection is stored and accessed via {{!!cuisine}}

1 Like

Even better you could use a filter to retrieve the existing values for a given field in the whole wiki, using the each operator. Then by adding a new cuisine to one tiddler manually, it becomes available to select for any future recipe automatically;

Eg untested [all[tiddlers]each[cuisine]get[cuisine]sort[]]

This is data driven rather than code driven.

1 Like

Thank you all for your advices, but I think I didn’t explain myself well.

I’m making some templates to use first in the Mehregam version that Mohanmad made. In this version inspired by Zettelkasten concept.
First, I define a macro in which all the fields that I am going to need and the different sections that I want the note to have are specified.
I call this tiddler in this case $:plugins/kookma/thinkup/macros/Recipe, its appearance is as follows:

\define createNewItem()
  <$action-sendmessage 
    $message="tm-new-tiddler" 
    title=<<unusedtitle """New $(new-item-title)$""">> 
    tags="[[$(currentTiddler)$]]" 
    foto="$:/plugins/kookma/thinkup/images/mr_avatar"
	caption="nombre de la receta"
    keywords=""	
	text=<<content>>
	enlace=""
    foto_pie="receta"		
	tipo_receta=""
	categoria=""
	modo_cocinado=""
	tiempo=""
	dificultad=""	
	raciones=""		
	pais=""
	region=""
    />
\end


\define content()

<table class="table-borderless source">
<tr><td>{{$:/modelo/recursos/iconos/knife-fork-fill}}</td><td>{{!!tipo_receta}}</td><td>{{$:/modelo/recursos/iconos/clock}}</td><td>{{!!tiempo}}</td><td>minutos</td><td>{{$:/modelo/recursos/iconos/people-fill}}</td><td>{{!!raciones}}</td><td>personas</td><td>{{$:/modelo/recursos/iconos/bar-chart-fill}}</td><td>{{!!dificultad}}</td></tr>
</table>


: <<.lorem>>

<$macrocall $name=image-pretty img={{!!foto}} align="right" caption={{!!foto_pie}} tooltip={{!!foto_pie}} alt=""/>

;Ingredientes

: """ 
<<.lorem>>
 """
<br>

;PreparaciĂłn

"""
<div>
<<.lorem>>

</div>
"""


\end

Then from a button the macro is executed and a tiddler is created with all the fields and sections that I have defined.
Once this tiddler has been created, which appears in editing mode, I have to fill in its different sections and fields.
It is at that moment when I would like to be able to choose a certain value for each of them without having to think about what their name was. But once the new tiddler is saved I don’t want to modify anything else through a dropdown.

Is it possible to do that?

Thank you very much.

What are “sections”? And when you say “fields”, do you mean you wish to create new fields+values or what do you actually mean?

And you want all of this to be done while in edit mode, right?

1 Like

Ok, let me explain.
The sections I am referring to: the Introduction of the recipe, the ingredients and the preparation.
I use the fields to display information in the recipe and also to later be able to make lists based on the needs I have.

Examples of fields would be: recipe duration, number of diners, recipe category, cooking mode, country of origin, etc…

The idea, if it can be done in a not very complicated way, is that I have a model with all the sections and fields that I need, in which I can fill in the data of the fields and choose, in those that I can, the values ​​of the fields depending on the recipe.

Right now, using this template, a tiddler is created which I fill in without problems, but when filling in the field data I always get lost because I’m not sure how I put it the last time. For example: Cocktails and drinks instead of Drinks and cocktails.
A solution that I found was in the template where I specify the fields to create, give them the value of all the possible answers, but then I have to go around deleting the unnecessary parts.

Thanks.

For sections, maybe you can use the stamp tool (that appears in the editor toolbar)? I.e create multiple stamp tools (one for each section type) listing the various options in the dropdown?

For the field values, you could perhaps have a selection type list show with options depending on the name of the field.

1 Like

For this use-case, I use the following workflow:

  1. Define a new “creation” tiddler
    This tiddler contains an input form based on <$select> and <$edit-text> widgets, in order to allow me to input the values of the fields of the to-be-created recipe tiddler. The form stores its state in state tiddlers, and the definition of the creation macro for individual recipes (in your case, createNewItem) is modified to use the contents of these state tiddlers. Example: replace modo_cocinado="" with modo_cocinado={{$:/state/modo_cocinado}}
    The form also includes a “Create” button, which triggers the actions of the createNewItem macro

  2. Create a “template” tiddler
    The text of this template tiddler contains all the sections used in the recipe, replacing your content macros, but also every field I need, with empty values, and a bunch of predefined tags.
    The createNewItem macro must be modified accordingly, in order to use the template tiddler as a template in the <tm-new-tiddler> message.

  3. A modified workflow:
    First open the creation tiddler, then fill-in the form, then click “Create”, et voilà !

Fred

1 Like

I like this workflow too, especially for tiddlers in which I add contents along time.

I just regret it lacks a way to add fields at the same time as it adds contents in the text. I mean if the stamp snippet contains:

!Duration

The recipe duration is {{!!duration}}

then insterting the snippet with the stamp tool won’t create the duration field at the same time.

I wish it would be possible to define custom actions bound to snippets…

Fred

If you make your own editor toolbar button it is common to use the action in the widget message https://tiddlywiki.com/#WidgetMessage%3A%20tm-edit-text-operation however you can trigger any action you want including one to create a field. However you need only use actionsetsield with or without a value, but in some ways it is of little use unless you do assign a value.

What I am not clear about is your creating fields without values then asking not to have to set a value?

I suspect you are interested in getting the user to fill out a set of temporary fields then click to create a new tiddler and transfer those temporary values to the new tiddler? eg temp-cuisine

  • If this is so using an edit-text widget to accept typed values with a select widget to select from existing values allows new or existing values to be entered or selected. Using the [all[tiddlers]each[cuisine]get[cuisine]sort[]] filter in the list within the the select widget, that sets the same field.
  • Then the new tiddler button includes cuisine={{!!temp-cuisine}}
1 Like

Thank you very much tw-FRed.
Your solution is exactly what I was thinking of. But I didn’t know how to implement it. I have found a kitchen Tw that uses the system you mention, I am trying to understand how it works and I already have it half working.
In the afternoon, if I have a moment, I’ll post my progress to see if I’m doing well.

Thank you

Hello TW-Tones.

You are right, what I am trying to do is make a model in which I can enter certain predefined values in the established fields and later create a tiddler with those data already entered.
I’ll take a look at the procedure you mentioned.
Thank you very much.

have a closer look at : https://tiddlywiki.com/#ActionCreateTiddlerWidget

1 Like

Thank you PMario.

I’ll take a close look at your suggestion to see if I can get something useful for the project I’m doing.

Hello everyone.
Following the instructions of tw-FRed and using The Recipe plugin (Recipe plugin — For storing your recipes) as a base, I have managed to make a template that generates a tiddler with the name of the recipe and with all the fields I need.
This is a summary of said template:

Nombre de la receta:
    <$edit-text
        tiddler='$:/temp/modelo/recetas/NuevaReceta'
        field=receta_nombre
        class='recipesearchbar'
    />

Tipo de receta:
<$select tiddler='$:/temp/modelo/recetas/NuevaReceta' field='receta_tipo' tooltip='Cambia el tipo de receta'>
<option value=''>-</option>
<option value='Acompañamiento'>Acompañamiento</option>
<option value='Cena'>Cena</option>
<option value='Desayuno'>Desayuno</option>
<option value='Entrante'>Entrante</option>
<option value='Merienda'>Postre</option>
<option value='Plato principal'>Plato principal</option>
<option value='Postre'>Postre</option>
<option value='Otros'>Otros</option>
</$select>

CategorĂ­a:
<$select tiddler='$:/temp/modelo/recetas/NuevaReceta' field='receta_categoria' tooltip='Elige la categorĂ­a de la receta'>
<option value=''>-</option>
<option value='Aperitivos y tapas'>Aperitivos y tapas</option>
<option value='Arroces y cereales'>Arroces y cereales</option>
<option value='Aves y caza'>Aves y caza</option>
<option value='Carne'>Carne</option>
<option value='Consejos de cocina'>Consejos de cocina</option>
<option value='CĂłcteles y bebidas'>CĂłcteles y bebidas</option>
<option value='Ensaladas'>Ensaladas</option>
<option value='Guisos y Potajes'>Guisos y Potajes</option>
<option value='Huevos y lácteos'>Huevos y lácteos</option>
<option value='Legumbres'>Legumbres</option>
<option value='Mariscos'>Mariscos</option>
<option value='Pan y bollerĂ­a'>Pan y bollerĂ­a</option>
<option value='Pasta'>Pasta</option>
<option value='Pescado'>Pescado</option>
<option value='Postres'>Postres</option>
<option value='Salsas'>Salsas</option>
<option value='Sopas y cremas'>Sopas y cremas</option>
<option value='Verduras'>Verduras</option>
</$select>

...

Foto:
<$edit-text
	tiddler='$:/temp/modelo/recetas/NuevaReceta'
	field=foto
	class='recipesearchbar'
	placeholder='Introduce la foto de la receta'
	tag=textarea
    />

Pie de foto:
<$edit-text
	tiddler='$:/temp/modelo/recetas/NuevaReceta'
	field=foto_pie
	class='recipesearchbar'
	placeholder='Introduce el texto para el pie de la foto'
	tag=textarea
    />

Keywords:
<$edit-text
	tiddler='$:/temp/modelo/recetas/NuevaReceta'
	field=keywords
	class='recipesearchbar'
	placeholder='Introduce las palabras clave para la receta'
	tag=textarea
    />

<$button>
<$action-createtiddler 
         $basetitle={{$:/temp/modelo/recetas/NuevaReceta'!!receta_nombre}} 
/>
<$action-setfield
            $tiddler={{$:/temp/modelo/recetas/NuevaReceta!!receta_nombre}}  
            receta_tipo={{$:/temp/modelo/recetas/NuevaReceta!!receta_tipo}}
            receta_categoria={{$:/temp/modelo/recetas/NuevaReceta!!receta_categoria}}
            receta_dificultad={{$:/temp/modelo/recetas/NuevaReceta!!receta_dificultad}}
            receta_modococinado={{$:/temp/modelo/recetas/NuevaReceta!!receta_modococinado}}
			receta_pais={{$:/temp/modelo/recetas/NuevaReceta!!receta_pais}}	
			receta_region={{$:/temp/modelo/recetas/NuevaReceta!!receta_region}}
			receta_picante={{$:/temp/modelo/recetas/NuevaReceta!!receta_picante}}						
			receta_temporada={{$:/temp/modelo/recetas/NuevaReceta!!receta_temporada}}
			receta_alergenos={{$:/temp/modelo/recetas/NuevaReceta!!receta_alergenos}}
			receta_raciones={{$:/temp/modelo/recetas/NuevaReceta!!receta_raciones}}
			receta_tiempo={{$:/temp/modelo/recetas/NuevaReceta!!receta_tiempo}}
			enlace={{$:/temp/modelo/recetas/NuevaReceta!!enlace}}
			foto={{$:/temp/modelo/recetas/NuevaReceta!!foto}}
			foto_pie={{$:/temp/modelo/recetas/NuevaReceta!!foto_pie}}
			keywords={{$:/temp/modelo/recetas/NuevaReceta!!keywords}}
			caption={{$:/temp/modelo/recetas/NuevaReceta!!caption}}
            tags={{$:/temp/modelo/recetas/DefaultTag}}
            icon='$:/images/fa5/solid/utensils'
/>

<$action-setfield
            $tiddler='$:/temp/modelo/recetas/NuevaReceta'
            receta_nombre=''
            receta_tipo=''
            receta_categoria=''
            receta_dificultad=''
            receta_modococinado=''
            receta_pais=''
            receta_region=''
            receta_picante=''
            receta_temporada=''
            receta_alergenos=''	
            receta_raciones=''
			receta_tiempo=''				
            enlace=''		
            foto=''
            foto_pie=''
            keywords=''
            caption=''
            text=''
            tags=''
/>

Añade receta
</$button>

Now what I don’t know is to use the model that I was using until now, I don’t know how to implement this. This is the template I was using with the Mehregan of Mohammad so far:

\define createNewItem()
  <$action-sendmessage 
	$message="tm-new-tiddler" 
	title=<<unusedtitle """New $(new-item-title)$""">> 
	tags="[[$(currentTiddler)$]]" 
	caption="nombre de la receta"
	text=<<content>>
	keywords=""	
	enlace="DirecciĂłn de la receta"    	
	foto="$:/plugins/kookma/thinkup/images/mr_avatar"
	foto_pie="Nombre de la foto"
	receta_categoria=""		
	receta_modococinado=""
	receta_tipo=""
	receta_temporada=""
	receta_raciones=""
	receta_tiempo=""		
	receta_dificultad=""
	receta_pais=""
	receta_region=""
	receta_alergenos=""
	receta_picante=""
    />

\end


\define content()

<table class="table-borderless source">
<tr><td>{{$:/modelo/recursos/iconos/knife-fork-fill}}</td><td>{{!!receta_tipo}}</td><td>{{$:/modelo/recursos/iconos/clock}}</td><td>{{!!receta_tiempo}}</td><td>minutos</td><td>{{$:/modelo/recursos/iconos/people-fill}}</td><td>{{!!receta_raciones}}</td><td>personas</td><td>{{$:/modelo/recursos/iconos/bar-chart-fill}}</td><td>{{!!receta_dificultad}}</td></tr>
</table>

---
<center>
''InformaciĂłn adicional: '' {{!!receta_picante}}, {{!!receta_alergenos}}, {{!!receta_modococinado}}, {{!!receta_pais}}: {{!!receta_region}}.
</center>

---


: <<.lorem>>

<$macrocall $name=image-pretty img={{!!foto}} align="right" caption={{!!foto_pie}} tooltip={{!!foto_pie}} alt=""/>

;Ingredientes
: """ 
<<.lorem>>
 """
;PreparaciĂłn
"""<p>

#<<.lorem>>

</p>"""

;Consejos
: """
<<.lorem>>
"""

\end

Can you tell me how to do this?
On the other hand, all ideas or improvements are welcome.

Thanks.

One more question.
How could I add text from the template to the final tiddler? Let me explain, I can from the template add fields with predefined values through a list or add values to fields through direct entry. But I can’t imagine how to enter text, for example the steps in the preparation of a cooking recipe, and dump it directly into the final tiddler but not form part of a field.
If it is difficult to do it this way, I simply edit the tiddler already created with the fields already filled in and enter the content sections: recipe introduction, ingredients, preparation steps and tips.

Thank you

Everything seems to be in place in your new template, except the actions seem to be in the wrong order: first you create the new tiddler, then you populate the fields of the template, and next you empty them.

Could you try to:

  • swap the $action-ceatetiddler and the first $action-setfield
  • in the $action-ceatetiddler
    • get rid of the ' character in the $basetitle value
    • add the parameter $template="$:/temp/modelo/recetas/NuevaReceta"

and see if it works ?

Fred

Hello tw-FRed. I understand that what you told me is this, right?

<$button>
<$action-createtiddler 
        $basetitle={{$:/temp/modelo/recetas/NuevaReceta!!receta_nombre}} 
		$template="$:/temp/modelo/recetas/NuevaReceta"
/>
<$action-setfield
            $tiddler='$:/temp/modelo/recetas/NuevaReceta'
            receta_nombre=''
            receta_tipo=''
            receta_categoria=''
            receta_dificultad=''
            receta_modococinado=''
            receta_pais=''
            receta_region=''
            receta_picante=''
            receta_temporada=''
            receta_alergenos=''	
            receta_raciones=''
			receta_tiempo=''				
            enlace=''		
            foto=''
            foto_pie=''
            keywords=''
            caption=''
            text=''
            tags=''
/>
<$action-setfield
            $tiddler={{$:/temp/modelo/recetas/NuevaReceta!!receta_nombre}}  
            receta_tipo={{$:/temp/modelo/recetas/NuevaReceta!!receta_tipo}}
            receta_categoria={{$:/temp/modelo/recetas/NuevaReceta!!receta_categoria}}
            receta_dificultad={{$:/temp/modelo/recetas/NuevaReceta!!receta_dificultad}}
            receta_modococinado={{$:/temp/modelo/recetas/NuevaReceta!!receta_modococinado}}
			receta_pais={{$:/temp/modelo/recetas/NuevaReceta!!receta_pais}}	
			receta_region={{$:/temp/modelo/recetas/NuevaReceta!!receta_region}}
			receta_picante={{$:/temp/modelo/recetas/NuevaReceta!!receta_picante}}						
			receta_temporada={{$:/temp/modelo/recetas/NuevaReceta!!receta_temporada}}
			receta_alergenos={{$:/temp/modelo/recetas/NuevaReceta!!receta_alergenos}}
			receta_raciones={{$:/temp/modelo/recetas/NuevaReceta!!receta_raciones}}
			receta_tiempo={{$:/temp/modelo/recetas/NuevaReceta!!receta_tiempo}}
			enlace={{$:/temp/modelo/recetas/NuevaReceta!!enlace}}
			foto={{$:/temp/modelo/recetas/NuevaReceta!!foto}}
			foto_pie={{$:/temp/modelo/recetas/NuevaReceta!!foto_pie}}
			keywords={{$:/temp/modelo/recetas/NuevaReceta!!keywords}}
			caption={{$:/temp/modelo/recetas/NuevaReceta!!caption}}
            tags={{$:/temp/modelo/recetas/DefaultTag}}
            icon='$:/images/fa5/solid/utensils'
/>


Añade receta
</$button>


If I do it this way, it creates a tiddler with its name as indicated in the form and all the required fields. But it doesn’t show me the data using the model. If I change the name of the model that I have previously put to $:/temp/model/recipes/NewRecipe, the magic happens, but the tiddler is deleted in its body as a result of the creation of the fields, so I cannot reuse again.

I have modified the model so that it is only as follows:

<table class="table-borderless source">
<tr><td>{{$:/modelo/recursos/iconos/knife-fork-fill}}</td><td>{{!!receta_tipo}}</td><td>{{$:/modelo/recursos/iconos/clock}}</td><td>{{!!receta_tiempo}}</td><td>minutos</td><td>{{$:/modelo/recursos/iconos/people-fill}}</td><td>{{!!receta_raciones}}</td><td>personas</td><td>{{$:/modelo/recursos/iconos/bar-chart-fill}}</td><td>{{!!receta_dificultad}}</td></tr>
</table>

---
<center>
''InformaciĂłn adicional: '' {{!!receta_picante}}, {{!!receta_alergenos}}, {{!!receta_modococinado}}, {{!!receta_pais}}: {{!!receta_region}}.
</center>

---


: <<.lorem>>

<$macrocall $name=image-pretty img={{!!foto}} align="right" caption={{!!foto_pie}} tooltip={{!!foto_pie}} alt=""/>

;Ingredientes
: """ 
<<.lorem>>
 """
;PreparaciĂłn
"""<p>

#<<.lorem>>

</p>"""

;Consejos
: """
<<.lorem>>
"""

Still not in the order I expected :wink:

This should do the trick for the first part (untested):

<$button>
<$action-setfield
            $tiddler={{$:/temp/modelo/recetas/NuevaReceta!!receta_nombre}}  
            receta_tipo={{$:/temp/modelo/recetas/NuevaReceta!!receta_tipo}}
            receta_categoria={{$:/temp/modelo/recetas/NuevaReceta!!receta_categoria}}
            receta_dificultad={{$:/temp/modelo/recetas/NuevaReceta!!receta_dificultad}}
            receta_modococinado={{$:/temp/modelo/recetas/NuevaReceta!!receta_modococinado}}
			receta_pais={{$:/temp/modelo/recetas/NuevaReceta!!receta_pais}}	
			receta_region={{$:/temp/modelo/recetas/NuevaReceta!!receta_region}}
			receta_picante={{$:/temp/modelo/recetas/NuevaReceta!!receta_picante}}						
			receta_temporada={{$:/temp/modelo/recetas/NuevaReceta!!receta_temporada}}
			receta_alergenos={{$:/temp/modelo/recetas/NuevaReceta!!receta_alergenos}}
			receta_raciones={{$:/temp/modelo/recetas/NuevaReceta!!receta_raciones}}
			receta_tiempo={{$:/temp/modelo/recetas/NuevaReceta!!receta_tiempo}}
			enlace={{$:/temp/modelo/recetas/NuevaReceta!!enlace}}
			foto={{$:/temp/modelo/recetas/NuevaReceta!!foto}}
			foto_pie={{$:/temp/modelo/recetas/NuevaReceta!!foto_pie}}
			keywords={{$:/temp/modelo/recetas/NuevaReceta!!keywords}}
			caption={{$:/temp/modelo/recetas/NuevaReceta!!caption}}
            tags={{$:/temp/modelo/recetas/DefaultTag}}
            icon='$:/images/fa5/solid/utensils'
/>
<$action-createtiddler 
        $basetitle={{$:/temp/modelo/recetas/NuevaReceta!!receta_nombre}} 
		$template="$:/temp/modelo/recetas/NuevaReceta"
/>
<$action-setfield
            $tiddler='$:/temp/modelo/recetas/NuevaReceta'
            receta_nombre=''
            receta_tipo=''
            receta_categoria=''
            receta_dificultad=''
            receta_modococinado=''
            receta_pais=''
            receta_region=''
            receta_picante=''
            receta_temporada=''
            receta_alergenos=''	
            receta_raciones=''
			receta_tiempo=''				
            enlace=''		
            foto=''
            foto_pie=''
            keywords=''
            caption=''
            text=''
            tags=''
/>


Añade receta
</$button>

And about the model, in order for the above code to work, the body of the $:/temp/modelo/recetas/NuevaReceta tiddler should contain your model’s code:

<table class="table-borderless source">
<tr><td>{{$:/modelo/recursos/iconos/knife-fork-fill}}</td><td>{{!!receta_tipo}}</td><td>{{$:/modelo/recursos/iconos/clock}}</td><td>{{!!receta_tiempo}}</td><td>minutos</td><td>{{$:/modelo/recursos/iconos/people-fill}}</td><td>{{!!receta_raciones}}</td><td>personas</td><td>{{$:/modelo/recursos/iconos/bar-chart-fill}}</td><td>{{!!receta_dificultad}}</td></tr>
</table>

---
<center>
''InformaciĂłn adicional: '' {{!!receta_picante}}, {{!!receta_alergenos}}, {{!!receta_modococinado}}, {{!!receta_pais}}: {{!!receta_region}}.
</center>

---


: <<.lorem>>

<$macrocall $name=image-pretty img={{!!foto}} align="right" caption={{!!foto_pie}} tooltip={{!!foto_pie}} alt=""/>

;Ingredientes
: """ 
<<.lorem>>
 """
;PreparaciĂłn
"""<p>

#<<.lorem>>

</p>"""

;Consejos
: """
<<.lorem>>
"""

Fred