LZ.setValueFromElement()
The LZ.setValueFromElement()
function sets (or updates) the value of the specified bucket to the specified element's value.
The function has the following signature:
setValueFromElement(bucketName, elementSelector, mode = "text", forceChange = false)
Where:
bucketName {string}
is the name of the bucket to be set/updated.elementSelector {string}
is a valid CSS selector 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 selector 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.setValueFromElement("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.setValueFromElement()
too.
This is a slower version of LZ.setValueFromElementId()
. Prefer that whenever possible.