<spanid="evennia-contrib-utils-fieldfill-fieldfill"></span><h1>evennia.contrib.utils.fieldfill.fieldfill<aclass="headerlink"href="#module-evennia.contrib.utils.fieldfill.fieldfill"title="Permalink to this headline">¶</a></h1>
<p>Easy fillable form</p>
<p>Contrib - Tim Ashley Jenkins 2018</p>
<p>This module contains a function that calls an easily customizable EvMenu - this
menu presents the player with a fillable form, with fields that can be filled
out in any order. Each field’s value can be verified, with the function
allowing easy checks for text and integer input, minimum and maximum values /
character lengths, or can even be verified by a custom function. Once the form
is submitted, the form’s data is submitted as a dictionary to any callable of
your choice.</p>
<p>The function that initializes the fillable form menu is fairly simple, and
includes the caller, the template for the form, and the callback(caller, result)
to which the form data will be sent to upon submission.</p>
<p>Form templates are defined as a list of dictionaries - each dictionary
represents a field in the form, and contains the data for the field’s name and
behavior. For example, this basic form template will allow a player to fill out
a brief character profile:</p>
<blockquote>
<div><p>PROFILE_TEMPLATE = [
{“fieldname”:”Name”, “fieldtype”:”text”},
{“fieldname”:”Age”, “fieldtype”:”number”},
{“fieldname”:”History”, “fieldtype”:”text”},
]</p>
</div></blockquote>
<p>This will present the player with an EvMenu showing this basic form:</p>
<blockquote>
<div><blockquote>
<div><dlclass="simple">
<dt>Name:</dt><dd><p>Age:</p>
</dd>
</dl>
</div></blockquote>
<p>History:</p>
</div></blockquote>
<p>While in this menu, the player can assign a new value to any field with the
syntax <field> = <new value>, like so:</p>
<blockquote>
<div><p>> name = Ashley
Field ‘Name’ set to: Ashley</p>
</div></blockquote>
<p>Typing ‘look’ by itself will show the form and its current values.</p>
<blockquote>
<div><blockquote>
<div><p>> look</p>
<blockquote>
<div><dlclass="simple">
<dt>Name: Ashley</dt><dd><p>Age:</p>
</dd>
</dl>
</div></blockquote>
</div></blockquote>
<p>History:</p>
</div></blockquote>
<p>Number fields require an integer input, and will reject any text that can’t
be converted into an integer.</p>
<blockquote>
<div><p>> age = youthful
Field ‘Age’ requires a number.
> age = 31
Field ‘Age’ set to: 31</p>
</div></blockquote>
<p>Form data is presented as an EvTable, so text of any length will wrap cleanly.</p>
<blockquote>
<div><blockquote>
<div><p>> history = EVERY MORNING I WAKE UP AND OPEN PALM SLAM[…]
Field ‘History’ set to: EVERY MORNING I WAKE UP AND[…]
> look</p>
<blockquote>
<div><dlclass="simple">
<dt>Name: Ashley</dt><dd><p>Age: 31</p>
</dd>
</dl>
</div></blockquote>
</div></blockquote>
<dlclass="simple">
<dt>History: EVERY MORNING I WAKE UP AND OPEN PALM SLAM A VHS INTO THE SLOT.</dt><dd><p>IT’S CHRONICLES OF RIDDICK AND RIGHT THEN AND THERE I START DOING
THE MOVES ALONGSIDE WITH THE MAIN CHARACTER, RIDDICK. I DO EVERY
MOVE AND I DO EVERY MOVE HARD.</p>
</dd>
</dl>
</div></blockquote>
<p>When the player types ‘submit’ (or your specified submit command), the menu
quits and the form’s data is passed to your specified function as a dictionary,
<codeclass="sig-name descname">node_formatter</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">nodetext</span></em>, <emclass="sig-param"><spanclass="n">optionstext</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#FieldEvMenu.node_formatter"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.FieldEvMenu.node_formatter"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats the entirety of the node.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>nodetext</strong> (<em>str</em>) – The node text as returned by <strong>self.nodetext_formatter</strong>.</p></li>
<li><p><strong>optionstext</strong> (<em>str</em>) – The options display as returned by <strong>self.options_formatter</strong>.</p></li>
<li><p><strong>caller</strong> (<em>Object</em><em>, </em><em>Account</em><em> or </em><em>None</em><em>, </em><em>optional</em>) – The caller of the node.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>node (str)</em>– The formatted node to display.</p>
<codeclass="sig-prename descclassname">evennia.contrib.utils.fieldfill.fieldfill.</code><codeclass="sig-name descname">menunode_fieldfill</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">caller</span></em>, <emclass="sig-param"><spanclass="n">raw_string</span></em>, <emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#menunode_fieldfill"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.menunode_fieldfill"title="Permalink to this definition">¶</a></dt>
<dd><p>This is an EvMenu node, which calls itself over and over in order to
allow a player to enter values into a fillable form. When the form is
submitted, the form data is passed to a callback as a dictionary.</p>
<codeclass="sig-prename descclassname">evennia.contrib.utils.fieldfill.fieldfill.</code><codeclass="sig-name descname">form_template_to_dict</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">formtemplate</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#form_template_to_dict"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.form_template_to_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Initializes a dictionary of form data from the given list-of-dictionaries
form template, as formatted above.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><p><strong>formtemplate</strong> (<em>list of dicts</em>) – Tempate for the form to be initialized.</p>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><em>formdata (dict)</em>– Dictionary of initalized form data.</p>
<codeclass="sig-prename descclassname">evennia.contrib.utils.fieldfill.fieldfill.</code><codeclass="sig-name descname">verify_online_player</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">caller</span></em>, <emclass="sig-param"><spanclass="n">value</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#verify_online_player"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.verify_online_player"title="Permalink to this definition">¶</a></dt>
<dd><p>Example ‘verify function’ that matches player input to an online character
or else rejects their input as invalid.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>caller</strong> (<em>obj</em>) – Player entering the form data.</p></li>
<li><p><strong>value</strong> (<em>str</em>) – String player entered into the form, to be verified.</p></li>
</ul>
</dd>
<dtclass="field-even">Returns</dt>
<ddclass="field-even"><p><p><em>matched_character (obj or False)</em>–</p>
<dlclass="simple">
<dt>dbref to a currently logged in</dt><dd><p>character object - reference to the object will be stored in
the form instead of a string. Returns False if no match is
<emclass="property">class </em><codeclass="sig-prename descclassname">evennia.contrib.utils.fieldfill.fieldfill.</code><codeclass="sig-name descname">CmdTestMenu</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="o">**</span><spanclass="n">kwargs</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#CmdTestMenu"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">key</code><emclass="property"> = 'testmenu'</em><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu.key"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">func</code><spanclass="sig-paren">(</span><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#CmdTestMenu.func"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu.func"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">aliases</code><emclass="property"> = []</em><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu.aliases"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">help_category</code><emclass="property"> = 'general'</em><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu.help_category"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">lock_storage</code><emclass="property"> = 'cmd:all();'</em><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu.lock_storage"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-name descname">search_index_entry</code><emclass="property"> = {'aliases': '', 'category': 'general', 'key': 'testmenu', 'no_prefix': ' ', 'tags': '', 'text': "\n This test command will initialize a menu that presents you with a form.\n You can fill out the fields of this form in any order, and then type in\n 'send' to send a message to another online player, which will reach them\n after a delay you specify.\n\n Usage:\n <field> = <new value>\n clear <field>\n help\n look\n quit\n send\n "}</em><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.CmdTestMenu.search_index_entry"title="Permalink to this definition">¶</a></dt>
<codeclass="sig-prename descclassname">evennia.contrib.utils.fieldfill.fieldfill.</code><codeclass="sig-name descname">sendmessage</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">obj</span></em>, <emclass="sig-param"><spanclass="n">text</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#sendmessage"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.sendmessage"title="Permalink to this definition">¶</a></dt>
<dd><p>Callback to send a message to a player.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>obj</strong> (<em>obj</em>) – Player to message.</p></li>
<codeclass="sig-prename descclassname">evennia.contrib.utils.fieldfill.fieldfill.</code><codeclass="sig-name descname">init_delayed_message</code><spanclass="sig-paren">(</span><emclass="sig-param"><spanclass="n">caller</span></em>, <emclass="sig-param"><spanclass="n">formdata</span></em><spanclass="sig-paren">)</span><aclass="reference internal"href="../_modules/evennia/contrib/utils/fieldfill/fieldfill.html#init_delayed_message"><spanclass="viewcode-link">[source]</span></a><aclass="headerlink"href="#evennia.contrib.utils.fieldfill.fieldfill.init_delayed_message"title="Permalink to this definition">¶</a></dt>
<dd><p>Initializes a delayed message, using data from the example form.</p>
<dlclass="field-list simple">
<dtclass="field-odd">Parameters</dt>
<ddclass="field-odd"><ulclass="simple">
<li><p><strong>caller</strong> (<em>obj</em>) – Character submitting the message.</p></li>
<li><p><strong>formdata</strong> (<em>dict</em>) – Data from submitted form.</p></li>