Predefined list in field?

Hi Fred.

If I do it as you say, when I hit the button to create the tiddler, it generates two tiddlers. If for example the name of the recipe that I have specified in a field is: Meat. It generates a tiddler called Meat and another called Meat1.
One contains the fields and the format according to the indicated model (Meat1) and the other tiddler only contains the fields (Meat).

If I do it as I put you in the previous comment, it only generates a tiddler.

On the other hand, I still have the problem with the model that I put in the tiddler $:/temp/model/recipes/NewRecipe, every time I generate a recipe the body of said tiddler is deleted and I no longer have it available for the next recipe.

I have tried to make the model used have the following address $template="$:/tino/model/recipes/RecipeTemplate" but in this way the generated tiddler contains the format of the model but none of the fields entered in the form.

What am I doing wrong?

Thanks a lot

Sorry I didn’t read the whole thread … but a guess.

The code should look as following. If you have all your variable definitions inside the button widget, you may have a problem with variables, since they are defined when the button widget is rendered. The code as shown will evaluate all variables, when the button is clicked.

\define testCreate()
<$action-createtiddler />
\end

<$button actions=<<testCreate>> >
Create Tiddler
</$button>

Hi @JuanPalomo,

This time I tested the code and it should work as expected…

The creation tiddler:

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}} 
		$template="$:/temp/modelo/recetas/NuevaReceta"
            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=''
            tags=''
/>


Añade receta
</$button>

What I did:

  • remove text="" from the <$action-setfield> widget, this part removed the body contents of the model each time the button was pressed
  • move tags=... and icon=... from the <$action-setfield> to the <$action-createtiddler> widget
  • remove the rest of the <$action-setfield> because you store the contents of the form directly in the model, so thanks to the template parameter it’s useless to copy the values to the new tiddler. The two exceptions were the icon and tags fields (they are constants, so you could define them directly in the model).

And next the model/template $:/temp/modelo/recetas/NuevaReceta:

<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

1 Like

@JuanPalomo,

In its current form, the code should work, but it contains some problems:

  • The template should not be stored in a temp tiddler (prefixed with $:/temp/...), because temp tiddlers are not supposed to be saved, and they can be lost when reloading the wiki.
  • The template body is copied in every recipe. It works, but if you want to change it later you will have to change it in every recipe. The preferred way consists in using ViewTemplates that are applied to tiddlers dynamically. For your use-case though, building a ViewTemplate might require a lot of work…

If you have some time, I would suggest you to:

  • rename the current template/model to another name, maybe $:/JuanPalomo/template
  • keep the creation tiddler form as-is
  • in the <$action-createtiddler> widget, change the $template parameter value to $:/JuanPalomo/template and add more lines for every field you want to populate with the form values, like this:
<$action-createtiddler 
        $basetitle={{$:/temp/modelo/recetas/NuevaReceta!!receta_nombre}} 
        $template="$:/JuanPalomo/template"
            tags={{$:/temp/modelo/recetas/DefaultTag}}
            icon='$:/images/fa5/solid/utensils'
            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}}
/>

And also you should follow @pmario’s advice, but I’ll leave it to him to guide you through this part :wink:

Fred

1 Like

The modifications that you have indicated work perfectly!
Now everything is as I had in mind. In the same way I have adapted the form according to your last advice and changed the name to the template and everything works fine.
The model that I have taken as a reference to adapt it to my needs, The Recipe plugin, does use a ViewTemplate. I’ve had a look at it but it seems to me that it still eludes me with my current level of knowledge, maybe later…
Anyway, I already have a much faster way to enter the pile of recipes from my wife and my mother and that they all have an identical appearance.

Thank you very much for taking your time to help me with this problem. :grinning:

Greetings.