Code sample: a simple interface to allow creation of a tiddler only if name validation is ok

Not fancy by any means (as in very quick and dirty), minus the code involved in creating the tiddler.

Just to demonstrate one approach to validating the tiddler name before enabling the “Save/OK/Whatever” button to proceed.

<table style="border:none;">

Nouveau Mot / New Word:
<$edit-text tiddler="$:/temp/NewTiddlerName" field="text" tag="input" default=""/>

<$let wordValidate={{{ [{$:/temp/NewTiddlerName!!text}is[blank]then[BLANK]] [{$:/temp/NewTiddlerName!!text}is[tiddler]then[EXISTS]] +[else[OK]] }}}>

<div style={{{ [[text-align:center;border:3px dotted ]] [<wordValidate>match[OK]then[green]else[red]] [[;]] +[join[]]}}}>
//<$text text={{{ [<wordValidate>match[BLANK]then[Aucun mot saisi.]] [<wordValidate>match[OK]then[C'est un mot qui peut être ajouté.]] [<wordValidate>match[EXISTS]then[Ce mot existe déjà.]] }}}/><br>
/ <$text text={{{ [<wordValidate>match[BLANK]then[No word entered.]] [<wordValidate>match[OK]then[That is a word that can be added.]] [<wordValidate>match[EXISTS]then[That word already exists.]] }}}/>
//
</div>


<div style="text-align:center;">
<$button disabled={{{ [<wordValidate>match[OK]then[no]else[yes]] }}}>
✔ Enregistrer / Save
</$button>
<$button>
<$action-sendmessage $message="tm-close-tiddler" $param=<<currentTiddler>>/>
❌ Annuler / Cancel
</$button>
</div>

</$let>

</table>
3 Likes