I have added custom text field for bank transfer method.
In template file:
<div class="payment-method" data-bind="css: {'_active': (getCode() == isChecked())}">
<div class="payment-method-title field choice">
<input type="radio"
name="payment[method]"
class="radio"
data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()" />
<label data-bind="attr: {'for': getCode()}" class="label"><span data-bind="text: getTitle()"></span></label>
</div>
<div class="payment-method-content">
<p data-bind="html: getInstructions()"></p>
<fieldset data-bind="attr: {class: 'fieldset payment items allbank ' + getCode(), id: 'payment_form_' + getCode()}">
<div class="field _required">
<label data-bind="attr: {for: getCode() + '_bankowner'}" class="label">
<span><!-- ko i18n: 'Account Owner'--><!-- /ko --></span>
</label>
<div class="control">
<input data-validate="{'required-entry':true}" type="text" name="payment[bankowner]" class="input-text" value=""
data-bind="attr: {
id: getCode() + '_bankowner',
title: $t('Account Owner'),
'data-container': getCode() + '-bankowner',
'data-validate': JSON.stringify({'required':true})},
valueUpdate: 'keyup' "/>
</div>
</div>
</fieldset>
<!-- ko foreach: getRegion('messages') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="payment-method-billing-address">
<!-- ko foreach: $parent.getRegion(getBillingAddressFormName()) -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="checkout-agreements-block">
<!-- ko foreach: $parent.getRegion('before-place-order') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<div class="actions-toolbar">
<div class="primary">
<button class="action primary checkout"
type="submit"
data-bind="
click: placeOrder,
attr: {'title': $t('Place Order')},
enable: (getCode() == isChecked()),
css: {disabled: !isPlaceOrderActionAllowed()}
"
disabled>
<span data-bind="i18n: 'Place Order'"></span>
</button>
</div>
</div>
</div>
</div>
In js:
define(
[
'ko',
'Magento_Checkout/js/view/payment/default',
'jquery'
],
function (ko, Component,$) {
'use strict';
return Component.extend({
defaults: {
template: 'Ibnab_Additional/payment/banktransfer'
},
getData: function() {
return {
'method': this.item.method,
'additional_data': {
'bankowner': $('#banktransfer_bankowner').val()
}
};
},
/**
* Get value of instruction field.
* @returns {String}
*/
getInstructions: function () {
return window.checkoutConfig.payment.instructions[this.item.method];
}
});
}
);
But the validation is not working .
How to validate field set when clicking place order button.
Ideas welcome...