LZ.setValueFromElementId()
The LZ.setValueFromElementId()
function sets (or updates) the value of the specified bucket to the specified element's value.
The function has the following signature:
setValueFromElementId(bucketName, elementId, mode = "text", forceChange = false)
Where:
bucketName {string}
is the name of the bucket to be set/updated.elementId {string}
is the HTML id to be used to get the element to be used as source.mode {("text"|"content")} (Default: "text")
specifies how to change the content of the element.forceChange {boolean} (Default: false)
represents whether or notlz-onchange
should be forcefully called.
If the element with the specified id does not exist, the action is aborted.
A simple example:
<p lz-reactive lz-bucket="myBucket></p> <p id="content-paragraph">This is my content.</p> <script> LZ.setValueFromElementId("myBucket", "content-paragraph"); </script>
If we specified "content"
as the mode, content-paragraph
could have had other HTML elements inside.
All the standard behaviour of LZ.setValue()
applies to LZ.setValueFromElementId()
too.
This is a faster version of LZ.setValueFromElement()
. Prefer this whenever possible.
For an example on how to use this function, check out the tabs example.