Go to page content

button

Makes a button with an action attached.

This is an easy way to make a button and attach one or more actions or a postback.

For example:

{% button text="Hello" action={alert text="Hello Word!"} %}

This show a button with the text “Hello”.  When clicked it will show an alert message with the text “Hello World!”.

Another example:

{% button text="Postback"  postback={my_postback arg1=1 arg2=2} %}

When clicked it will call the event/2 function in the resource that served the page.  The function will be called as:

event({postback, {mypostback, [{arg1,1},{arg2,2}]}, TriggerId, TargetId}, Context)

Where TriggerId and TargetId are both the HTML id of the button.

The button scomp accepts the following arguments:

ArgumentDescriptionExample
textThe text on the button, defaults to “Submit”text="click me"
postbackAn event sent to the delegate or the resource serving the page.postback="hello"
delegateThe name of the erlang module to be called for handling the postback.delegate="myresource"
actionThe action to be triggered when the button is clicked.  There can be more than one action argument.action={show target="msg"}
idId of the button.id=#submit
classThe css class of the button.  This argument can be repeated to add multiple classes.class="submit"
styleThe css style of the button.style="color: #fc0"
typeThe type attribute of the button.type="submit"
titleThe title attribute of the button.title="click to submit"
disabledThe disabled attribute of the button, set to true or false.  When the button is disabled then the class "disabled" id added to the class list.disabled=true

This page is part of the Zotonic documentation, which is licensed under the Apache License 2.0.