What can be learned here:
<fx-submission>
<fx-send>
action<fx-message>
actionOk, nice - we have a todo list that will be gone when we reload the browser or leave the page.
We need a way to store our data. Let’s add a submission which will go into our model
<fx-submission id="save"
method="post"
url="#echo"
replace="instance"
instance="todo-list">
</fx-submission>
Due to technical limitations on this static site we use the builtin ‘#echo’ target for this tutorial that will just return the data it gets in and replaces another instance with it. This is to simulate what is usually happening when sending data via http.
What does this do?
id
to identify a submissionTo trigger a save operation you usually want a button.
... UI ...
<fx-trigger>
<button>Save</button>
<fx-send submission="save"></fx-send>
</fx-trigger>
Put together
Watch the ‘Data Inspector’ on the right. Intially there will be 2 data instances listed by their id.
Data Inspector is a tool that helps during development to see the live content of your data instances.
The instance live separate from the DOM and therefore cannot be seen in their actual state by inspecting
with developer tools.
You can just add it within any <fx-fore>
element.
After hitting the ‘Save’ button the instance ’todo-list’ will be identical to the ‘default’ instance.
This means that our submission has been executed and has send its data to the ‘#echo’ submission, that gets back the same data and replaced the ‘saved-list’ instance.
You may have noticed a message in the lower left after hitting ‘save’.
Let’s add the missing line i omitted from above code.
<fx-submission id="save"
method="post"
url="#echo"
replace="instance"
instance="saved-list">
<fx-message event="submit-done">your todo list has been saved</fx-message>
</fx-submission>
This adds a <fx-message>
element to the submission that will react to the ‘submit-done’ event
that is fired when a submission successfully returned.
The message element defaults to a toast message that disappears after a delay.
With the event
attribute the message action attaches to its parent element and reacts to ‘submit-done’ in this case.
This technique is used all over Fore to attach event handlers that in turn will run an action.