mix-replace
mix-replace
click bellow and replace me
mix-replace
click bellow and replace me
mix-update
click bellow and upate me
mix-remove
mix-remove
mix-cover
mix-get + mix-before + mix-ttl
Click on the hiperlink. The mix-cover will appear while the fetch request is being executed. Then, the mix-cover will be hidden and the response will be placed above the link.
Submit a form with the data in it. Enter your name and press the button. The name will be sent to the server. The server will reply with a message. While all that is taking place, the button will not be clickable (disabled). Once the response is received, the button will be clickable again.
Note: This example uses the action attribute in the form.
<form action="/users"
mix-post>
<input name="user-name"
placeholder="user name">
<button id="btn">
Create profile
</button>
</form>
<template
mix-replace="#btn">
<div>
Your profile is created
</div>
</template>
Submit a form with the data in it. Enter your name and press the button. The name will be sent to the server. The server will reply with a template that will instruct the UI to change the button with the content inside the template.
Note: This example does not use the action attribute in the form.
<form
mix-post="/users">
<input name="user-name"
placeholder="user name">
<button id="btn">
Create profile
</button>
</form>
<template
mix-replace="#btn">
<div>
Your profile is created
</div>
</template>
Only send the data inside one input element. There are situations in which the whole form should not be sent, but only one element. Think of an email that needs to be verified to make sure that it can be used to signup. If the email is invalid or taken, a message should be shown to the user. This action be be triggered onblur by using a combination of mix-post and mix-blur. This will validate the email once the user clicks outside the input field. Keep in mind, only that field is passed to the server and not the entire form.
<form
mix-post="/verify-email">
<input name="email">
<span id="message"></span>
</form>
<template
mix-replace="#message">
Your profile is created
</template>
Click on the hyper link and a new element shows on before it. The new element is also clickable :)
<a href="item"
id="item"
mix-get>
Click here.
A new element shows on top
</a>
<div
mix-before="#item"
mix-get="item">
This element came from the server.
Click me again!
</div>
Click on the hyper link that doesn't have a href and a new element shows on before it.
<a id="item"
mix-get="item">
Click here.
A new element shows on top
</a>
<div
mix-before="#item">
New element from the server
</div>
Submit a form with the data in it. Since PUT is used to update a resource, the id of the resource is usually part of the URL.
Note: This example uses the action attribute in the form.
<form
action="/users/1"
mix-put>
<input name="user-name"
placeholder="user name">
<button>
Update profile
</button>
<div id="message"></div>
</form>
<template
mix-update="#message">
<div mix-ttl="2000" mix-fade-out>
Profile updated
</div>
</template>
Replace an element in the DOM with a whole new element
<div
id="ex-replace-03">
I am going to be replaced
with a new element when you click
on the button bellow.
</div>
<button
mix-post="ex-replace-03">
Replace element on top
</button>
<template
mix-replace="#ex-replace-03">
<div>
I am the new element
</div>
</template>
Replace multiple elements with a new one
<div
class="ex-replace-02">
I am going to be replaced
</div>
<div class="ex-replace-02">
I am going to be replaced
</div>
<div class="ex-replace-02">
And I too, will be replaced
</div>
<button mix-post="ex-replace-02">
Replace all elements
</button>
<template
mix-replace=".ex-replace-02">
<div>
I am the new element
</div>
</template>
Update an element in the DOM. The element doesn't change, but the content of it (innerHTML) is updated.
Update multiple elements with a new one
Update an element with a new one. The new element will be removed after a few seconds because mix-ttl is used.
Update multiple elements with new ones. The new elements will be removed after a few seconds because mix-ttl is used.
Create a new element in the DOM before the selected one(s). It is possible to select any element by tag, id, class, or anything that is supported in query selectors.
Update multiple elements with a new one
Update an element with a new one. The new element will be removed after a few seconds because mix-ttl is used.
Update multiple elements with new ones. The new elements will be removed after a few seconds because mix-ttl is used.
A DOM element sends a HTTP request. The response would like to trigger a function in the client (JavaScript function). The function is a custom one that expects to get 1 argument. The argument is the data contained inside the template tag.
<script>
function show_data(data){
alert(data)
}
</script>
<button
mix-get="/data">
Get JSON data
</button>
<template
mix-function="show_data">
[{'id':1,'name':'A'}]
</template>