{"result":{"depiction_url":null,"edges":{"in_module":{"objects":[{"created":"2020-05-30T05:47:56Z","object_id":{"id":1303,"is_a":["text","documentation","reference","module"],"name":"doc_module_mod_wires","title":"mod_wires","uri":"https:\/\/zotonic.com\/id\/1303"},"seq":1000000}],"predicate":{"id":333,"is_a":["meta","predicate"],"name":"in_module","title":{"_type":"trans","tr":{"en":"In module"}},"uri":"https:\/\/zotonic.com\/id\/in_module"}},"references":{"objects":[{"created":"2020-05-30T05:47:56Z","object_id":{"id":326,"is_a":["meta","category"],"name":"template_action","title":"Actions","uri":"https:\/\/test.zotonic.com\/id\/326"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1510,"is_a":["text","documentation","reference","template_action"],"name":"doc_template_action_action_show","title":"show","uri":"https:\/\/zotonic.com\/id\/1510"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1511,"is_a":["text","documentation","reference","template_action"],"name":"doc_template_action_action_hide","title":"hide","uri":"https:\/\/zotonic.com\/id\/1511"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1630,"is_a":["text","documentation","reference","template_action"],"name":"doc_template_action_action_postback","title":"postback","uri":"https:\/\/zotonic.com\/id\/1630"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1302,"is_a":["text","documentation","developerguide"],"name":"doc_developerguide_server_browser_interaction","title":{"_type":"trans","tr":{"en":"Handle a browser event with a wire"}},"uri":"https:\/\/zotonic.com\/id\/1302"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1323,"is_a":["text","documentation","reference","template_scomp"],"name":"doc_template_scomp_scomp_live","title":"live","uri":"https:\/\/zotonic.com\/id\/1323"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1324,"is_a":["text","documentation","reference","module"],"name":"doc_module_mod_mqtt","title":"mod_mqtt","uri":"https:\/\/zotonic.com\/id\/1324"},"seq":1000000}],"predicate":{"id":332,"is_a":["meta","predicate"],"name":"references","title":{"_type":"trans","tr":{"en":"References"}},"uri":"https:\/\/zotonic.com\/id\/references"}},"refers":{"objects":[{"created":"2026-09-09T13:48:06Z","object_id":{"id":1323,"is_a":["text","documentation","reference","template_scomp"],"name":"doc_template_scomp_scomp_live","title":"live","uri":"https:\/\/zotonic.com\/id\/1323"},"seq":1000000},{"created":"2026-09-09T13:48:06Z","object_id":{"id":1324,"is_a":["text","documentation","reference","module"],"name":"doc_module_mod_mqtt","title":"mod_mqtt","uri":"https:\/\/zotonic.com\/id\/1324"},"seq":1000000},{"created":"2026-09-09T13:48:06Z","object_id":{"id":1510,"is_a":["text","documentation","reference","template_action"],"name":"doc_template_action_action_show","title":"show","uri":"https:\/\/zotonic.com\/id\/1510"},"seq":1000000},{"created":"2026-09-09T13:48:06Z","object_id":{"id":1511,"is_a":["text","documentation","reference","template_action"],"name":"doc_template_action_action_hide","title":"hide","uri":"https:\/\/zotonic.com\/id\/1511"},"seq":1000000},{"created":"2026-09-09T13:48:06Z","object_id":{"id":1630,"is_a":["text","documentation","reference","template_action"],"name":"doc_template_action_action_postback","title":"postback","uri":"https:\/\/zotonic.com\/id\/1630"},"seq":1000000}],"predicate":{"id":2409,"is_a":["meta","predicate"],"name":"refers","title":{"_type":"trans","tr":{"en":"Refers"}},"uri":"https:\/\/zotonic.com\/id\/refers"}},"relation":{"objects":[{"created":"2020-05-30T05:47:56Z","object_id":{"id":1324,"is_a":["text","documentation","reference","module"],"name":"doc_module_mod_mqtt","title":"mod_mqtt","uri":"https:\/\/zotonic.com\/id\/1324"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":1403,"is_a":["text","documentation","reference","template_scomp"],"name":"doc_template_scomp_scomp_wire_args","title":"wire_args","uri":"https:\/\/zotonic.com\/id\/1403"},"seq":1000000},{"created":"2020-05-30T05:47:56Z","object_id":{"id":326,"is_a":["meta","category"],"name":"template_action","title":"Actions","uri":"https:\/\/test.zotonic.com\/id\/326"},"seq":1000000}],"predicate":{"id":303,"is_a":["meta","predicate"],"name":"relation","title":{"_type":"trans","tr":{"nl":"Relatie","en":"Relation"}},"uri":"http:\/\/purl.org\/dc\/terms\/relation"}},"subject":{"objects":[{"created":"2026-09-09T13:48:07Z","object_id":{"id":2555,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_reference","title":"Reference","uri":"https:\/\/zotonic.com\/id\/2555"},"seq":1},{"created":"2026-09-09T13:48:07Z","object_id":{"id":2563,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_frontend_developer","title":"Frontend developer","uri":"https:\/\/zotonic.com\/id\/2563"},"seq":2},{"created":"2026-09-09T13:48:07Z","object_id":{"id":2583,"is_a":["categorization","keyword","keyword_domain"],"name":"zotonic_topic_user_interface_and_interaction","title":"User interface and interaction","uri":"https:\/\/zotonic.com\/id\/2583"},"seq":3},{"created":"2026-09-09T13:48:07Z","object_id":{"id":2623,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_scomp","title":"Server component","uri":"https:\/\/zotonic.com\/id\/2623"},"seq":4},{"created":"2026-09-09T13:48:07Z","object_id":{"id":2624,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_wire_action","title":"Wire action","uri":"https:\/\/zotonic.com\/id\/2624"},"seq":5},{"created":"2026-09-09T13:48:07Z","object_id":{"id":2673,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_javascript","title":"JavaScript","uri":"https:\/\/zotonic.com\/id\/2673"},"seq":6}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":1327,"is_a":["text","documentation","reference","template_scomp"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1327"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_template_scomp_scomp_wire","page_url":{"en":"https:\/\/zotonic.com\/docs\/1327\/wire","x-default":"https:\/\/zotonic.com\/docs\/1327\/wire"},"preview_url":null,"resource":{"version":3356,"pivot_location_lat":null,"title":"wire","is_authoritative":true,"body":"<p>Connect actions and events to a HTML element.<\/p>\n<p>The wire tag is the basis for most Ajax interaction on web pages. It allows to connect actions to HTML elements.\nExamples of <a href=\"\/id\/template_action#actions\">Actions<\/a> are <a href=\"\/id\/doc_template_action_action_show\" class=\"doc-reference doc-reference-action\"><code>action#show<\/code><\/a> \/\n<a href=\"\/id\/doc_template_action_action_hide\" class=\"doc-reference doc-reference-action\"><code>action#hide<\/code><\/a> elements or <a href=\"\/id\/doc_template_action_action_postback\" class=\"doc-reference doc-reference-action\"><code>action#postback<\/code><\/a> to the server.<\/p>\n<h2>Wire actions to an element<\/h2>\n<p>The primary use of wire is to connect an action to a HTML element or javascript event.<\/p>\n<p>Example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{% wire id=&quot;show&quot; action={show target=&quot;message&quot;} %}\n&lt;a id=&quot;show&quot; href=&quot;#&quot;&gt;Click to show a message&lt;\/a&gt;\n&lt;p style=&quot;display: none&quot; id=&quot;message&quot;&gt;Hello World!&lt;\/p&gt;\n<\/code><\/pre>\n<p>A click on the link will show the message “Hello World!”.<\/p>\n<h2>Wire postbacks to the server<\/h2>\n<p>Wire can post an event back to the server. Use for this the “postback” argument:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{% wire id=&quot;mybutton&quot; postback={hello world=&quot;round&quot;} %}\n&lt;button id=&quot;mybutton&quot;&gt;Post event to server&lt;\/button&gt;\n<\/code><\/pre>\n<p>When the button is clicked the event function of the page controller will be called as:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">event(#postback{message=Postback, trigger=TriggerId, target=TargetId}, Context).\n<\/code><\/pre>\n<p>Where “Postback” will be <code>{hello, [{world,&lt;&lt;&quot;round&quot;&gt;&gt;}]}<\/code> and both “TriggerId” and “TargetId” will be <code>&lt;&lt;&quot;mybutton&quot;&gt;&gt;<\/code>.<\/p>\n<h2>Wire form submit events<\/h2>\n<p>Wire is also used to connect a form to the event routine handling the form.<\/p>\n<p>Example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{% wire id=&quot;myform&quot; type=&quot;submit&quot; postback=&quot;some_tag&quot; action={toggle target=&quot;message&quot;} %}\n&lt;form id=&quot;myform&quot; method=&quot;post&quot; action=&quot;postback&quot;&gt;\n  &lt;input type=&quot;text&quot; name=&quot;title&quot; value=&quot;&quot; \/&gt;\n  &lt;button id=&quot;mybutton&quot; type=&quot;submit&quot;&gt;Submit&lt;\/button&gt;\n&lt;\/form&gt;\n<\/code><\/pre>\n<p>The wire tag redirects the submit of the form to the event routine of the controller. A submit will also toggle the\nvisibility of the “message” element on the page. Note that the action is “postback”, this is obligatory.<\/p>\n<p>The event routine will be called as:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">event(#submit{message=Tag, form=FormId, target=TargetId}, Context).\n<\/code><\/pre>\n<p>Where Tag will be the postback set by the wire tag (in the example the atom <code>some_tag<\/code>) and FormId and TargetId are both\nthe HTML id of the submitted form. The posted input fields can be fetched using <code>z_context:get_q\/2<\/code>,\n<code>z_context:get_q_all\/1<\/code> or <code>z_context:get_q_validated\/2<\/code>.<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">Title = z_context:get_q(&lt;&lt;&quot;title&quot;&gt;&gt;, Context),\nAllArgs = z_context:get_q_all(Context);\n<\/code><\/pre>\n<p>There are some extra arguments added to every form post:<\/p>\n<table class=\"table\"><thead><tr><th>Post argument<\/th><th>Description<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td><code>z_trigger_id<\/code><\/td><td>Id of the HTML element that triggered the submit.<\/td><td><code>&lt;&lt;&quot;mybutton&quot;&gt;&gt;<\/code><\/td><\/tr><tr><td><code>z_pageid<\/code><\/td><td>Id of the page in the browser, used to connect comet and other communication between the browser and the server.<\/td><td><code>&lt;&lt;&quot;1uTsbzIsWqmPpF32&quot;&gt;&gt;<\/code><\/td><\/tr><tr><td><code>postback<\/code><\/td><td>Signed postback set by the wire tag. Handled internally.<\/td><td><\/td><\/tr><\/tbody><\/table>\n<h2>Wire to the page load or unload<\/h2>\n<p>A <code>{% wire %}<\/code> without an id will bind the actions and\/or postback to the window instead of an element. Omitting a type\nas well will execute all actions and\/or postback on page load.<\/p>\n<p>Example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{% wire action={alert text=&quot;Welcome to this page.&quot;} %}\n<\/code><\/pre>\n<p>The type “unload” will execute all actions and\/or postback when leaving the page:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{% wire type=&quot;unload&quot; action={alert text=&quot;Bye.&quot;} %}\n<\/code><\/pre>\n<h2>Call a wire action from JavaScript<\/h2>\n<p>Use <code>{% wire name=&quot;myname&quot; %}<\/code> to define a named action and trigger it from JavaScript with <code>z_event(&quot;myname&quot;)<\/code>.\nSee: <a href=\"\/id\/doc_developerguide_server_browser_interaction#guide-named-wire\">Wires<\/a>.<\/p>\n<h2>Wire an action to a MQTT topic<\/h2>\n<div class=\"admonition note\"><p class=\"first admonition-title\">Note<\/p><p class=\"last\"><a href=\"\/id\/doc_module_mod_mqtt\" class=\"doc-reference doc-reference-module\"><code>module#mod_mqtt<\/code><\/a> must be enabled before wiring to a topic<\/p><\/div>\n<p>Use <code>{% wire type={mqtt topic=... topic=...} %}<\/code> to connect to one or more MQTT topics.<\/p>\n<p>Example:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">{% wire type={mqtt topic=&quot;~site\/public\/hello&quot;} action={growl text=&quot;hello&quot;} %}\n<\/code><\/pre>\n<p>And in Erlang this will trigger the above <em>growl<\/em>:<\/p>\n<pre class=\"notranslate\"><code class=\"notranslate language-erlang\">z_mqtt:publish(&lt;&lt;&quot;~site\/public\/hello&quot;&gt;&gt;, &lt;&lt;&gt;&gt;, z_acl:sudo(z:c(mysite))).\n<\/code><\/pre>\n<p>See also <a href=\"\/id\/doc_template_scomp_scomp_live\" class=\"doc-reference doc-reference-scomp\"><code>scomp#live<\/code><\/a><\/p>\n<h2>Arguments<\/h2>\n<p>The wire tag accepts the following arguments:<\/p>\n<table class=\"table\"><thead><tr><th>Argument<\/th><th>Description<\/th><th>Example<\/th><\/tr><\/thead><tbody><tr><td><code>id<\/code><\/td><td>HTML id of the element the action gets connected to. When the id is not given then the event is bound to the window.<\/td><td><code>id=”mybutton”<\/code><\/td><\/tr><tr><td><code>type<\/code><\/td><td>The type of the event triggering the action. Defaults to “click”. Other types are: “enterkey”, “interval”, “continuation”, “submit” or one of the jQuery events “blur”, “focus”, “load”, “resize”, “scroll”, “unload”, “beforeunload”, “click”, “dblclick”, “mousedown”, “mouseup”, “mousemove”, “mouseover”, “mouseout”, “mouseenter”, “mouseleave”, “change”, “select”, “keydown”, “keypress”, “keyup” or “error”.  The types can be extended by modules using the <code>#action_event_type<\/code> notification. The type must be a tuple, an example is the <code>{mqtt topic=...}<\/code> type provided by <a href=\"\/id\/doc_module_mod_mqtt\" class=\"doc-reference doc-reference-module\"><code>module#mod_mqtt<\/code><\/a><\/td><td><code>type=”submit”<\/code><\/td><\/tr><tr><td><code>propagate<\/code><\/td><td>Specify this when you don’t want the event to be canceled after handling the wire. Useful for event types like focus, click etc. .. versionadded:: 0.6.1<\/td><td><code>propagate<\/code><\/td><\/tr><tr><td><code>target<\/code><\/td><td>Possible target for the action. The meaning of this argument depends on the action, defaults to id.<\/td><td><\/td><\/tr><tr><td><code>action<\/code><\/td><td>Action wired to the element. This parameter can be repeated to wire more than one action at a time. The value is a single or a list of action records.<\/td><td><code>action={toggle target=&quot;message&quot;}<\/code><\/td><\/tr><tr><td><code>postback<\/code><\/td><td>Postback that will be sent to the event handler of the controller or the delegate. Either a string, which will be sent as an atom, or a tagged property list. The example will be in Erlang <code>{myevent, [{foo,1},{bar,2}]}<\/code>.<\/td><td><code>postback=&quot;ajaxevent&quot; postback={myevent foo=1 bar=2}<\/code><\/td><\/tr><tr><td><code>delegate<\/code><\/td><td>Name of the Erlang module that will receive the postback. Defaults to the controller that handled the page request.<\/td><td><code>delegate=&quot;event_handler&quot;<\/code><\/td><\/tr><\/tbody><\/table>","slug":"wire","is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"2068e839f3315520d41ff64bd2c609cf94c5290da553e498e7041f5736c334c7","is_featured":false,"content_group_id":{"id":2551,"is_a":["meta","content_group"],"name":"content_group_imported_docs","title":"Imported documentation","uri":"https:\/\/zotonic.com\/id\/content_group_imported_docs"},"category_id":{"id":327,"is_a":["meta","category"],"name":"template_scomp","title":"Scomp","uri":"https:\/\/zotonic.com\/id\/template_scomp"},"doc_source_path":"apps\/zotonic_mod_wires\/src\/scomps\/scomp_wires_wire.erl","publication_start":"2023-01-30T19:23:59Z","github_url":"https:\/\/github.com\/zotonic\/zotonic\/blob\/master\/apps\/zotonic_mod_wires\/src\/scomps\/scomp_wires_wire.erl","pivot_location_lng":null,"doc_source_kind":"scomp","name":"doc_template_scomp_scomp_wire","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2020-05-30T05:47:18Z","uri":null,"doc_status":"current","is_dependent":false,"erlang_app":"zotonic_mod_wires","publication_end":"9999-06-01T00:00:00Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"privacy":0,"doc_source_commit":"c19e5c894d3bd01b57581e2af43e176d42c6877a\n","erlang_module":"scomp_wires_wire","creator_id":{"id":336,"is_a":["person","robot"],"name":"gitbot","title":"Git","uri":"https:\/\/zotonic.com\/id\/336"},"modified":"2026-10-08T10:41:04Z","title_slug":"wire"},"uri":"https:\/\/zotonic.com\/id\/1327","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/1327"}},"status":"ok"}