I want to call on click function in template file with script type "text/x-magento-init".
Then please tell me how can i do this?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityAdd below code in js file:
define(['jquery'], function ($) {
'use strict';
return function (config) {
console.log(config);
$(document).on("click","input[id^='your-button-id-here']", function () {
console.log('click');
});
};
});
Add below code in template file:
<script type="text/x-magento-init">
{
"*": {
"Your component name here": {"url":"value"}
}
}
</script>
.js file add this function
myfunction: function () {
$('#your_id').click(function () {
//your code goes here
});
},`
Your template data-bind should be:
<input type="text"
id="your_field_id"
name="name"
data-validate="{required:true}"
data-bind='
attr: {title: $t("title")},
value: fieldvalue,
event: { "input": myfunction}'
class="input-text"/>