Binding Events On Dynamically Generated DOM Elements Knockout + Magento 2Magento 2 Knockout JS data binding issueCheckout uiComponent (input field) rendered multiple times: how do I apply viewmodel functionality to current input field only?Magento 2 - Jquery not triggering any events for Product attribute input fields in new product formMagento 2: How to submit form on checkbox click?Knockout JS custom scope bindingMagento 2 - Update quantity and totals of cart page without page reload?How to update DOM element in Knockout JsKnockout binding js to templateMagento2 custom Knockout bindingHow to create custom form in Magento 2.2.3
Does fossil fuels use since 1990 account for half of all the fossil fuels used in history?
What is the most difficult concept to grasp in Calculus 1?
What is the hottest thing in the universe?
What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?
Running code generated in realtime in JavaScript with eval()
Why did IBM make the PC BIOS source code public?
Does an Irish VISA WARNING count as "refused entry at the border of any country other than the UK?"
Go to last file in vim
How do I ask for 2-3 days per week remote work in a job interview?
Is there a name for the technique in songs/poems, where the rhyming pattern primes the listener for a certain line, which never comes?
Random Stripe Webhook Issues
Is there a fallacy about "appeal to 'big words'"?
Bringing Power Supplies on Plane?
Are employers legally allowed to pay employees in goods and services equal to or greater than the minimum wage?
How can God warn people of the upcoming rapture without disrupting society?
Doesn't the speed of light limit imply the same electron can be annihilated twice?
How would armour (and combat) change if the fighter didn't need to actually wear it?
What unique challenges/limitations will I face if I start a career as a pilot at 45 years old?
Help, I cannot decide when to start the story
Will using a resistor in series with a LED to control its voltage increase the total energy expenditure?
What are the odds of rolling specific ability score totals in D&D?
Do I have to cite common CS algorithms?
Did DOS zero out the BSS area when it loaded a program?
If a person claims to know anything could it be disproven by saying 'prove that we are not in a simulation'?
Binding Events On Dynamically Generated DOM Elements Knockout + Magento 2
Magento 2 Knockout JS data binding issueCheckout uiComponent (input field) rendered multiple times: how do I apply viewmodel functionality to current input field only?Magento 2 - Jquery not triggering any events for Product attribute input fields in new product formMagento 2: How to submit form on checkbox click?Knockout JS custom scope bindingMagento 2 - Update quantity and totals of cart page without page reload?How to update DOM element in Knockout JsKnockout binding js to templateMagento2 custom Knockout bindingHow to create custom form in Magento 2.2.3
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am working on a module where i have generated few DOM elements dynamically. But when i am trying to call certain function on some events then its not getting called. Here is the code sample. Here you can see i am calling getData method on "change" event but its not being called
getData: function()
var data = this._super();
data.additional_data.bank_type = $('input[name="payment\[bank_type\]"]:checked').val();
data.additional_data.emi = $('input[name="payment\[emi\]"]:checked').val();
data.additional_data.email = this.getEmail();
console.log($('input[name="payment\[emi\]"]:checked').val());
return data;
,
getEmi: function (emiCount)
var total = priceUtils.formatPrice(quote.totals().grand_total, quote.getPriceFormat());
var rowTotal = quote.totals().grand_total;
var item = '';
var html = '';
var i;
for (i=1; i<=emiCount; i++ )
if (i==1)
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" +
"</li>";
else
rowTotal = parseInt(rowTotal)/i;
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>"+i+" Taksit, Aylık Taksit: "+priceUtils.formatPrice(rowTotal, quote.getPriceFormat())+" Toplam: "+total+"</label>" +
"</li>";
html = html+item;
console.log(html);
$('.emi-list').html(html);
,
magento2 knockoutjs
add a comment |
I am working on a module where i have generated few DOM elements dynamically. But when i am trying to call certain function on some events then its not getting called. Here is the code sample. Here you can see i am calling getData method on "change" event but its not being called
getData: function()
var data = this._super();
data.additional_data.bank_type = $('input[name="payment\[bank_type\]"]:checked').val();
data.additional_data.emi = $('input[name="payment\[emi\]"]:checked').val();
data.additional_data.email = this.getEmail();
console.log($('input[name="payment\[emi\]"]:checked').val());
return data;
,
getEmi: function (emiCount)
var total = priceUtils.formatPrice(quote.totals().grand_total, quote.getPriceFormat());
var rowTotal = quote.totals().grand_total;
var item = '';
var html = '';
var i;
for (i=1; i<=emiCount; i++ )
if (i==1)
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" +
"</li>";
else
rowTotal = parseInt(rowTotal)/i;
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>"+i+" Taksit, Aylık Taksit: "+priceUtils.formatPrice(rowTotal, quote.getPriceFormat())+" Toplam: "+total+"</label>" +
"</li>";
html = html+item;
console.log(html);
$('.emi-list').html(html);
,
magento2 knockoutjs
add a comment |
I am working on a module where i have generated few DOM elements dynamically. But when i am trying to call certain function on some events then its not getting called. Here is the code sample. Here you can see i am calling getData method on "change" event but its not being called
getData: function()
var data = this._super();
data.additional_data.bank_type = $('input[name="payment\[bank_type\]"]:checked').val();
data.additional_data.emi = $('input[name="payment\[emi\]"]:checked').val();
data.additional_data.email = this.getEmail();
console.log($('input[name="payment\[emi\]"]:checked').val());
return data;
,
getEmi: function (emiCount)
var total = priceUtils.formatPrice(quote.totals().grand_total, quote.getPriceFormat());
var rowTotal = quote.totals().grand_total;
var item = '';
var html = '';
var i;
for (i=1; i<=emiCount; i++ )
if (i==1)
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" +
"</li>";
else
rowTotal = parseInt(rowTotal)/i;
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>"+i+" Taksit, Aylık Taksit: "+priceUtils.formatPrice(rowTotal, quote.getPriceFormat())+" Toplam: "+total+"</label>" +
"</li>";
html = html+item;
console.log(html);
$('.emi-list').html(html);
,
magento2 knockoutjs
I am working on a module where i have generated few DOM elements dynamically. But when i am trying to call certain function on some events then its not getting called. Here is the code sample. Here you can see i am calling getData method on "change" event but its not being called
getData: function()
var data = this._super();
data.additional_data.bank_type = $('input[name="payment\[bank_type\]"]:checked').val();
data.additional_data.emi = $('input[name="payment\[emi\]"]:checked').val();
data.additional_data.email = this.getEmail();
console.log($('input[name="payment\[emi\]"]:checked').val());
return data;
,
getEmi: function (emiCount)
var total = priceUtils.formatPrice(quote.totals().grand_total, quote.getPriceFormat());
var rowTotal = quote.totals().grand_total;
var item = '';
var html = '';
var i;
for (i=1; i<=emiCount; i++ )
if (i==1)
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" +
"</li>";
else
rowTotal = parseInt(rowTotal)/i;
item = "<li>" +
"<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" +
"<label class='label' for='emi" + i + "'>"+i+" Taksit, Aylık Taksit: "+priceUtils.formatPrice(rowTotal, quote.getPriceFormat())+" Toplam: "+total+"</label>" +
"</li>";
html = html+item;
console.log(html);
$('.emi-list').html(html);
,
magento2 knockoutjs
magento2 knockoutjs
asked Jul 22 '18 at 20:20
Abhijeet kumar sharmaAbhijeet kumar sharma
14314 bronze badges
14314 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You did not mention on which html element you are trying to call change event.Can you tell me more about binding template.
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
add a comment |
I used js code like.
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*jshint browser:true jquery:true*/
/*global alert*/
define([
"jquery",
'ko',
'uiComponent',
'Magento_Ui/js/modal/alert',
"jquery/ui",
"mage/translate",
"mage/mage",
"mage/validation"
], function ($, ko, Component, alert, mage)
"use strict";
var totalCustomer= ko.observableArray([]);
var results= ko.observableArray([]);
function feedShow(name, email)
var self = this;
self.name = name;
self.email = email;
return Component.extend(
productList: ko.observableArray([]),
initialize: function()
this._super();
,
/** Initialize observable properties */
initObservable: function ()
this._super()
.observe('msgSaved')
;
this.uname = ko.observable('');
this.email = ko.observable('');
this.phone = ko.observable('');
this.msg = ko.observable('');
return this;
,
/**
* Validate feedback form
*/
validateForm: function ()
var form = '#feedback-form';
return $(form).validation() && $(form).validation('isValid');
,
submitFeedback: function ()
/* $.ajax(this.getFeedbackUrl).done(
function()
this.msgSaved(true)
.bind(this)
);*/
if (!this.validateForm())
return;
var data = 'name':this.uname(),'email':this.email(),'phone':this.phone(),'message':this.msg(),'status':0;
// if(this.validateForm())
//
// console.log(data);
$.ajax(
url: this.getFeedbackUrl,
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.msgSaved(true);
this.uname('testing');
alert(
content: $.mage.__('Thanks for Submitting.')
);
,
complete: this._ajaxComplete
);
,
totalfeeds:function()
console.log('test');
$.ajax(
url:'http://magento2.local/feedback/entry/show',
type: 'post',
dataType: 'json',
contentType: 'application/json',
context: this,
showLoader:true,
beforeSend: this._ajaxBeforeSend,
success: function (response)
var jsonTempStringified = JSON.stringify(response);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
this.productList(jsonTempStringifiedParsed);
// results(jsonTempStringifiedParsed);
,
complete: this._ajaxComplete
);
,
deleteFeeds:function(parent,data)
alert(
content: 'Are you sure want to delete record!'
);
var jsonTempStringified = JSON.stringify(data);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
var fid = jsonTempStringifiedParsed.fid;
var data = 'fid':fid;
$.ajax(
url:'http://magento2.local/feedback/entry/delete',
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.totalfeeds();
,
complete: this._ajaxComplete
);
,
defaults:
msgSaved: false,
template: 'Smart_Feedback/feedback',
);
);
Binding template .html file.
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div>
<!-- ko ifnot: msgSaved -->
<form method="post" class="feedback" id="feedback-form" data-role="feedback-form" data-bind="submit: submitFeedback">
<fieldset class="fieldset">
<legend class="legend"><span><p data-bind="i18n: 'You can post your feedback here.'"></p></span></legend><br>
<div class="field name required">
<label for="name" class="label"><span>Name</span></label>
<div class="control">
<input type="text" data-validate="required:true"
class="input-text" title="Name"
id="user_name" aria-required="true"
data-bind="value:uname,attr: 'data-validate': JSON.stringify(required:true),
">
</div>
</div>
<div class="field email required">
<label for="email" class="label"><span>Email</span></label>
<div class="control">
<input type="email" data-validate="required:true" data-bind="value:email,attr: 'data-validate': JSON.stringify(required:true,'validate-email':true),
" class="input-text" title="Email" id="email" aria-required="true" >
</div>
</div>
<div class="field telephone">
<label for="telephone" class="label"><span>Phone Number</span></label>
<div class="control">
<input type="text" class="input-text" value="" title="Phone Number" id="telephone" data-bind="value:phone">
</div>
</div>
<div class="field comment required">
<label for="comment" class="label"><span>Feedback message</span></label>
<div class="control">
<textarea data-validate="required:true" rows="3" cols="5" class="input-text" title="What’s on your mind?" id="comment" name="comment" aria-required="true"
data-bind="value:msg"></textarea>
</div>
</div>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<input type="hidden" value="" id="hideit" name="hideit">
<input type="submit" class="action primary" data-bind="value: $t('Submit Feedback')" />
<button data-bind="attr: title: $t('totalfeeds'), click: totalfeeds" class="action primary">Total Feeds</button>
<button data-bind="click: totalfeeds">click me</button>
<li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value="">
<label class='label' for='emi'>Test</label>
</li>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody data-bind="foreach: productList">
<tr>
<td data-bind="text: fid"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
<td><a href="#" data-bind="click: function(data,event)$parent.deleteFeeds($parent,data);">Remove</a></td>
</tr>
</tbody>
</table>
<!-- /ko -->
<!-- ko if: msgSaved -->
<p data-bind="i18n: 'Feedback message posted for review.'"></p>
<!-- /ko -->
</div>
Please check above radio element with change event with Test Label.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f235443%2fbinding-events-on-dynamically-generated-dom-elements-knockout-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You did not mention on which html element you are trying to call change event.Can you tell me more about binding template.
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
add a comment |
You did not mention on which html element you are trying to call change event.Can you tell me more about binding template.
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
add a comment |
You did not mention on which html element you are trying to call change event.Can you tell me more about binding template.
You did not mention on which html element you are trying to call change event.Can you tell me more about binding template.
answered Jul 26 '18 at 4:02
Charul TyagiCharul Tyagi
8131 silver badge14 bronze badges
8131 silver badge14 bronze badges
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
add a comment |
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
please have a look at getEmi method. I have bing the method getData in html item = "<li>" + "<input type='radio' name='payment[emi_type]' data-bind='event: change: getData' id='emi" + i + "' value='" + i + "'>" + "<label class='label' for='emi" + i + "'>Tek Ödeme, Toplam: "+total+"</label>" + "</li>";
– Abhijeet kumar sharma
Jul 26 '18 at 13:58
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
I used the same radio element in my code and it is working fine and calling the function of JS. I used this in .html file in which we binds the data.Put like this <li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value=""> <label class='label' for='emi'>Test</label> </li> I am also editing my post what i have the code.
– Charul Tyagi
Jul 27 '18 at 4:36
add a comment |
I used js code like.
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*jshint browser:true jquery:true*/
/*global alert*/
define([
"jquery",
'ko',
'uiComponent',
'Magento_Ui/js/modal/alert',
"jquery/ui",
"mage/translate",
"mage/mage",
"mage/validation"
], function ($, ko, Component, alert, mage)
"use strict";
var totalCustomer= ko.observableArray([]);
var results= ko.observableArray([]);
function feedShow(name, email)
var self = this;
self.name = name;
self.email = email;
return Component.extend(
productList: ko.observableArray([]),
initialize: function()
this._super();
,
/** Initialize observable properties */
initObservable: function ()
this._super()
.observe('msgSaved')
;
this.uname = ko.observable('');
this.email = ko.observable('');
this.phone = ko.observable('');
this.msg = ko.observable('');
return this;
,
/**
* Validate feedback form
*/
validateForm: function ()
var form = '#feedback-form';
return $(form).validation() && $(form).validation('isValid');
,
submitFeedback: function ()
/* $.ajax(this.getFeedbackUrl).done(
function()
this.msgSaved(true)
.bind(this)
);*/
if (!this.validateForm())
return;
var data = 'name':this.uname(),'email':this.email(),'phone':this.phone(),'message':this.msg(),'status':0;
// if(this.validateForm())
//
// console.log(data);
$.ajax(
url: this.getFeedbackUrl,
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.msgSaved(true);
this.uname('testing');
alert(
content: $.mage.__('Thanks for Submitting.')
);
,
complete: this._ajaxComplete
);
,
totalfeeds:function()
console.log('test');
$.ajax(
url:'http://magento2.local/feedback/entry/show',
type: 'post',
dataType: 'json',
contentType: 'application/json',
context: this,
showLoader:true,
beforeSend: this._ajaxBeforeSend,
success: function (response)
var jsonTempStringified = JSON.stringify(response);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
this.productList(jsonTempStringifiedParsed);
// results(jsonTempStringifiedParsed);
,
complete: this._ajaxComplete
);
,
deleteFeeds:function(parent,data)
alert(
content: 'Are you sure want to delete record!'
);
var jsonTempStringified = JSON.stringify(data);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
var fid = jsonTempStringifiedParsed.fid;
var data = 'fid':fid;
$.ajax(
url:'http://magento2.local/feedback/entry/delete',
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.totalfeeds();
,
complete: this._ajaxComplete
);
,
defaults:
msgSaved: false,
template: 'Smart_Feedback/feedback',
);
);
Binding template .html file.
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div>
<!-- ko ifnot: msgSaved -->
<form method="post" class="feedback" id="feedback-form" data-role="feedback-form" data-bind="submit: submitFeedback">
<fieldset class="fieldset">
<legend class="legend"><span><p data-bind="i18n: 'You can post your feedback here.'"></p></span></legend><br>
<div class="field name required">
<label for="name" class="label"><span>Name</span></label>
<div class="control">
<input type="text" data-validate="required:true"
class="input-text" title="Name"
id="user_name" aria-required="true"
data-bind="value:uname,attr: 'data-validate': JSON.stringify(required:true),
">
</div>
</div>
<div class="field email required">
<label for="email" class="label"><span>Email</span></label>
<div class="control">
<input type="email" data-validate="required:true" data-bind="value:email,attr: 'data-validate': JSON.stringify(required:true,'validate-email':true),
" class="input-text" title="Email" id="email" aria-required="true" >
</div>
</div>
<div class="field telephone">
<label for="telephone" class="label"><span>Phone Number</span></label>
<div class="control">
<input type="text" class="input-text" value="" title="Phone Number" id="telephone" data-bind="value:phone">
</div>
</div>
<div class="field comment required">
<label for="comment" class="label"><span>Feedback message</span></label>
<div class="control">
<textarea data-validate="required:true" rows="3" cols="5" class="input-text" title="What’s on your mind?" id="comment" name="comment" aria-required="true"
data-bind="value:msg"></textarea>
</div>
</div>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<input type="hidden" value="" id="hideit" name="hideit">
<input type="submit" class="action primary" data-bind="value: $t('Submit Feedback')" />
<button data-bind="attr: title: $t('totalfeeds'), click: totalfeeds" class="action primary">Total Feeds</button>
<button data-bind="click: totalfeeds">click me</button>
<li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value="">
<label class='label' for='emi'>Test</label>
</li>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody data-bind="foreach: productList">
<tr>
<td data-bind="text: fid"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
<td><a href="#" data-bind="click: function(data,event)$parent.deleteFeeds($parent,data);">Remove</a></td>
</tr>
</tbody>
</table>
<!-- /ko -->
<!-- ko if: msgSaved -->
<p data-bind="i18n: 'Feedback message posted for review.'"></p>
<!-- /ko -->
</div>
Please check above radio element with change event with Test Label.
add a comment |
I used js code like.
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*jshint browser:true jquery:true*/
/*global alert*/
define([
"jquery",
'ko',
'uiComponent',
'Magento_Ui/js/modal/alert',
"jquery/ui",
"mage/translate",
"mage/mage",
"mage/validation"
], function ($, ko, Component, alert, mage)
"use strict";
var totalCustomer= ko.observableArray([]);
var results= ko.observableArray([]);
function feedShow(name, email)
var self = this;
self.name = name;
self.email = email;
return Component.extend(
productList: ko.observableArray([]),
initialize: function()
this._super();
,
/** Initialize observable properties */
initObservable: function ()
this._super()
.observe('msgSaved')
;
this.uname = ko.observable('');
this.email = ko.observable('');
this.phone = ko.observable('');
this.msg = ko.observable('');
return this;
,
/**
* Validate feedback form
*/
validateForm: function ()
var form = '#feedback-form';
return $(form).validation() && $(form).validation('isValid');
,
submitFeedback: function ()
/* $.ajax(this.getFeedbackUrl).done(
function()
this.msgSaved(true)
.bind(this)
);*/
if (!this.validateForm())
return;
var data = 'name':this.uname(),'email':this.email(),'phone':this.phone(),'message':this.msg(),'status':0;
// if(this.validateForm())
//
// console.log(data);
$.ajax(
url: this.getFeedbackUrl,
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.msgSaved(true);
this.uname('testing');
alert(
content: $.mage.__('Thanks for Submitting.')
);
,
complete: this._ajaxComplete
);
,
totalfeeds:function()
console.log('test');
$.ajax(
url:'http://magento2.local/feedback/entry/show',
type: 'post',
dataType: 'json',
contentType: 'application/json',
context: this,
showLoader:true,
beforeSend: this._ajaxBeforeSend,
success: function (response)
var jsonTempStringified = JSON.stringify(response);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
this.productList(jsonTempStringifiedParsed);
// results(jsonTempStringifiedParsed);
,
complete: this._ajaxComplete
);
,
deleteFeeds:function(parent,data)
alert(
content: 'Are you sure want to delete record!'
);
var jsonTempStringified = JSON.stringify(data);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
var fid = jsonTempStringifiedParsed.fid;
var data = 'fid':fid;
$.ajax(
url:'http://magento2.local/feedback/entry/delete',
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.totalfeeds();
,
complete: this._ajaxComplete
);
,
defaults:
msgSaved: false,
template: 'Smart_Feedback/feedback',
);
);
Binding template .html file.
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div>
<!-- ko ifnot: msgSaved -->
<form method="post" class="feedback" id="feedback-form" data-role="feedback-form" data-bind="submit: submitFeedback">
<fieldset class="fieldset">
<legend class="legend"><span><p data-bind="i18n: 'You can post your feedback here.'"></p></span></legend><br>
<div class="field name required">
<label for="name" class="label"><span>Name</span></label>
<div class="control">
<input type="text" data-validate="required:true"
class="input-text" title="Name"
id="user_name" aria-required="true"
data-bind="value:uname,attr: 'data-validate': JSON.stringify(required:true),
">
</div>
</div>
<div class="field email required">
<label for="email" class="label"><span>Email</span></label>
<div class="control">
<input type="email" data-validate="required:true" data-bind="value:email,attr: 'data-validate': JSON.stringify(required:true,'validate-email':true),
" class="input-text" title="Email" id="email" aria-required="true" >
</div>
</div>
<div class="field telephone">
<label for="telephone" class="label"><span>Phone Number</span></label>
<div class="control">
<input type="text" class="input-text" value="" title="Phone Number" id="telephone" data-bind="value:phone">
</div>
</div>
<div class="field comment required">
<label for="comment" class="label"><span>Feedback message</span></label>
<div class="control">
<textarea data-validate="required:true" rows="3" cols="5" class="input-text" title="What’s on your mind?" id="comment" name="comment" aria-required="true"
data-bind="value:msg"></textarea>
</div>
</div>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<input type="hidden" value="" id="hideit" name="hideit">
<input type="submit" class="action primary" data-bind="value: $t('Submit Feedback')" />
<button data-bind="attr: title: $t('totalfeeds'), click: totalfeeds" class="action primary">Total Feeds</button>
<button data-bind="click: totalfeeds">click me</button>
<li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value="">
<label class='label' for='emi'>Test</label>
</li>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody data-bind="foreach: productList">
<tr>
<td data-bind="text: fid"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
<td><a href="#" data-bind="click: function(data,event)$parent.deleteFeeds($parent,data);">Remove</a></td>
</tr>
</tbody>
</table>
<!-- /ko -->
<!-- ko if: msgSaved -->
<p data-bind="i18n: 'Feedback message posted for review.'"></p>
<!-- /ko -->
</div>
Please check above radio element with change event with Test Label.
add a comment |
I used js code like.
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*jshint browser:true jquery:true*/
/*global alert*/
define([
"jquery",
'ko',
'uiComponent',
'Magento_Ui/js/modal/alert',
"jquery/ui",
"mage/translate",
"mage/mage",
"mage/validation"
], function ($, ko, Component, alert, mage)
"use strict";
var totalCustomer= ko.observableArray([]);
var results= ko.observableArray([]);
function feedShow(name, email)
var self = this;
self.name = name;
self.email = email;
return Component.extend(
productList: ko.observableArray([]),
initialize: function()
this._super();
,
/** Initialize observable properties */
initObservable: function ()
this._super()
.observe('msgSaved')
;
this.uname = ko.observable('');
this.email = ko.observable('');
this.phone = ko.observable('');
this.msg = ko.observable('');
return this;
,
/**
* Validate feedback form
*/
validateForm: function ()
var form = '#feedback-form';
return $(form).validation() && $(form).validation('isValid');
,
submitFeedback: function ()
/* $.ajax(this.getFeedbackUrl).done(
function()
this.msgSaved(true)
.bind(this)
);*/
if (!this.validateForm())
return;
var data = 'name':this.uname(),'email':this.email(),'phone':this.phone(),'message':this.msg(),'status':0;
// if(this.validateForm())
//
// console.log(data);
$.ajax(
url: this.getFeedbackUrl,
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.msgSaved(true);
this.uname('testing');
alert(
content: $.mage.__('Thanks for Submitting.')
);
,
complete: this._ajaxComplete
);
,
totalfeeds:function()
console.log('test');
$.ajax(
url:'http://magento2.local/feedback/entry/show',
type: 'post',
dataType: 'json',
contentType: 'application/json',
context: this,
showLoader:true,
beforeSend: this._ajaxBeforeSend,
success: function (response)
var jsonTempStringified = JSON.stringify(response);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
this.productList(jsonTempStringifiedParsed);
// results(jsonTempStringifiedParsed);
,
complete: this._ajaxComplete
);
,
deleteFeeds:function(parent,data)
alert(
content: 'Are you sure want to delete record!'
);
var jsonTempStringified = JSON.stringify(data);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
var fid = jsonTempStringifiedParsed.fid;
var data = 'fid':fid;
$.ajax(
url:'http://magento2.local/feedback/entry/delete',
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.totalfeeds();
,
complete: this._ajaxComplete
);
,
defaults:
msgSaved: false,
template: 'Smart_Feedback/feedback',
);
);
Binding template .html file.
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div>
<!-- ko ifnot: msgSaved -->
<form method="post" class="feedback" id="feedback-form" data-role="feedback-form" data-bind="submit: submitFeedback">
<fieldset class="fieldset">
<legend class="legend"><span><p data-bind="i18n: 'You can post your feedback here.'"></p></span></legend><br>
<div class="field name required">
<label for="name" class="label"><span>Name</span></label>
<div class="control">
<input type="text" data-validate="required:true"
class="input-text" title="Name"
id="user_name" aria-required="true"
data-bind="value:uname,attr: 'data-validate': JSON.stringify(required:true),
">
</div>
</div>
<div class="field email required">
<label for="email" class="label"><span>Email</span></label>
<div class="control">
<input type="email" data-validate="required:true" data-bind="value:email,attr: 'data-validate': JSON.stringify(required:true,'validate-email':true),
" class="input-text" title="Email" id="email" aria-required="true" >
</div>
</div>
<div class="field telephone">
<label for="telephone" class="label"><span>Phone Number</span></label>
<div class="control">
<input type="text" class="input-text" value="" title="Phone Number" id="telephone" data-bind="value:phone">
</div>
</div>
<div class="field comment required">
<label for="comment" class="label"><span>Feedback message</span></label>
<div class="control">
<textarea data-validate="required:true" rows="3" cols="5" class="input-text" title="What’s on your mind?" id="comment" name="comment" aria-required="true"
data-bind="value:msg"></textarea>
</div>
</div>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<input type="hidden" value="" id="hideit" name="hideit">
<input type="submit" class="action primary" data-bind="value: $t('Submit Feedback')" />
<button data-bind="attr: title: $t('totalfeeds'), click: totalfeeds" class="action primary">Total Feeds</button>
<button data-bind="click: totalfeeds">click me</button>
<li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value="">
<label class='label' for='emi'>Test</label>
</li>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody data-bind="foreach: productList">
<tr>
<td data-bind="text: fid"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
<td><a href="#" data-bind="click: function(data,event)$parent.deleteFeeds($parent,data);">Remove</a></td>
</tr>
</tbody>
</table>
<!-- /ko -->
<!-- ko if: msgSaved -->
<p data-bind="i18n: 'Feedback message posted for review.'"></p>
<!-- /ko -->
</div>
Please check above radio element with change event with Test Label.
I used js code like.
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
/*jshint browser:true jquery:true*/
/*global alert*/
define([
"jquery",
'ko',
'uiComponent',
'Magento_Ui/js/modal/alert',
"jquery/ui",
"mage/translate",
"mage/mage",
"mage/validation"
], function ($, ko, Component, alert, mage)
"use strict";
var totalCustomer= ko.observableArray([]);
var results= ko.observableArray([]);
function feedShow(name, email)
var self = this;
self.name = name;
self.email = email;
return Component.extend(
productList: ko.observableArray([]),
initialize: function()
this._super();
,
/** Initialize observable properties */
initObservable: function ()
this._super()
.observe('msgSaved')
;
this.uname = ko.observable('');
this.email = ko.observable('');
this.phone = ko.observable('');
this.msg = ko.observable('');
return this;
,
/**
* Validate feedback form
*/
validateForm: function ()
var form = '#feedback-form';
return $(form).validation() && $(form).validation('isValid');
,
submitFeedback: function ()
/* $.ajax(this.getFeedbackUrl).done(
function()
this.msgSaved(true)
.bind(this)
);*/
if (!this.validateForm())
return;
var data = 'name':this.uname(),'email':this.email(),'phone':this.phone(),'message':this.msg(),'status':0;
// if(this.validateForm())
//
// console.log(data);
$.ajax(
url: this.getFeedbackUrl,
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.msgSaved(true);
this.uname('testing');
alert(
content: $.mage.__('Thanks for Submitting.')
);
,
complete: this._ajaxComplete
);
,
totalfeeds:function()
console.log('test');
$.ajax(
url:'http://magento2.local/feedback/entry/show',
type: 'post',
dataType: 'json',
contentType: 'application/json',
context: this,
showLoader:true,
beforeSend: this._ajaxBeforeSend,
success: function (response)
var jsonTempStringified = JSON.stringify(response);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
this.productList(jsonTempStringifiedParsed);
// results(jsonTempStringifiedParsed);
,
complete: this._ajaxComplete
);
,
deleteFeeds:function(parent,data)
alert(
content: 'Are you sure want to delete record!'
);
var jsonTempStringified = JSON.stringify(data);
var jsonTempStringifiedParsed = JSON.parse(jsonTempStringified);
var fid = jsonTempStringifiedParsed.fid;
var data = 'fid':fid;
$.ajax(
url:'http://magento2.local/feedback/entry/delete',
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: this._ajaxBeforeSend,
success: function (response)
this.totalfeeds();
,
complete: this._ajaxComplete
);
,
defaults:
msgSaved: false,
template: 'Smart_Feedback/feedback',
);
);
Binding template .html file.
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<div>
<!-- ko ifnot: msgSaved -->
<form method="post" class="feedback" id="feedback-form" data-role="feedback-form" data-bind="submit: submitFeedback">
<fieldset class="fieldset">
<legend class="legend"><span><p data-bind="i18n: 'You can post your feedback here.'"></p></span></legend><br>
<div class="field name required">
<label for="name" class="label"><span>Name</span></label>
<div class="control">
<input type="text" data-validate="required:true"
class="input-text" title="Name"
id="user_name" aria-required="true"
data-bind="value:uname,attr: 'data-validate': JSON.stringify(required:true),
">
</div>
</div>
<div class="field email required">
<label for="email" class="label"><span>Email</span></label>
<div class="control">
<input type="email" data-validate="required:true" data-bind="value:email,attr: 'data-validate': JSON.stringify(required:true,'validate-email':true),
" class="input-text" title="Email" id="email" aria-required="true" >
</div>
</div>
<div class="field telephone">
<label for="telephone" class="label"><span>Phone Number</span></label>
<div class="control">
<input type="text" class="input-text" value="" title="Phone Number" id="telephone" data-bind="value:phone">
</div>
</div>
<div class="field comment required">
<label for="comment" class="label"><span>Feedback message</span></label>
<div class="control">
<textarea data-validate="required:true" rows="3" cols="5" class="input-text" title="What’s on your mind?" id="comment" name="comment" aria-required="true"
data-bind="value:msg"></textarea>
</div>
</div>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<input type="hidden" value="" id="hideit" name="hideit">
<input type="submit" class="action primary" data-bind="value: $t('Submit Feedback')" />
<button data-bind="attr: title: $t('totalfeeds'), click: totalfeeds" class="action primary">Total Feeds</button>
<button data-bind="click: totalfeeds">click me</button>
<li><input type='radio' name='emi_type' data-bind='event: change: totalfeeds' id='emi' value="">
<label class='label' for='emi'>Test</label>
</li>
</div>
</div>
</form>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Action</th>
</tr>
</thead>
<tbody data-bind="foreach: productList">
<tr>
<td data-bind="text: fid"></td>
<td data-bind="text: name"></td>
<td data-bind="text: email"></td>
<td><a href="#" data-bind="click: function(data,event)$parent.deleteFeeds($parent,data);">Remove</a></td>
</tr>
</tbody>
</table>
<!-- /ko -->
<!-- ko if: msgSaved -->
<p data-bind="i18n: 'Feedback message posted for review.'"></p>
<!-- /ko -->
</div>
Please check above radio element with change event with Test Label.
answered Jul 27 '18 at 4:43
Charul TyagiCharul Tyagi
8131 silver badge14 bronze badges
8131 silver badge14 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f235443%2fbinding-events-on-dynamically-generated-dom-elements-knockout-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown