diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js index dd643840e95..21a105da3fa 100644 --- a/addons/payment/static/src/js/payment_form.js +++ b/addons/payment/static/src/js/payment_form.js @@ -57,25 +57,29 @@ odoo.define('payment.payment_form', function (require) { console.warn('payment_form: unset partner_id when adding new token; things could go wrong'); } var form_data = this.getFormData(inputs_form); - var empty_inputs = false; + var wrong_input = false; inputs_form.toArray().forEach(function (element) { - if (element.dataset.isRequired) { - if (element.value.length === 0) { + //skip the check of non visible inputs + if ($(element).attr('type') == 'hidden') { + return true; + } + $(element).closest('div.form-group').removeClass('has-error'); + $(element).siblings( ".o_invalid_field" ).remove(); + //force check of forms validity (useful for Firefox that refill forms automatically on f5) + $(element).trigger("focusout"); + if (element.dataset.isRequired && element.value.length === 0) { $(element).closest('div.form-group').addClass('has-error'); - empty_inputs = true; - } - else { - $(element).closest('div.form-group').removeClass('has-error'); - } + $(element).closest('div.form-group').append('
Please fill all the inputs required.
') - ); + if (wrong_input) { return; } @@ -106,7 +110,7 @@ odoo.define('payment.payment_form', function (require) { else { self.displayError( _t('Server Error'), - _t("We are not able to add your payment method at the moment.
")); + _t('e.g. Your credit card details are wrong. Please verify.')); } // here we remove the 'processing' icon from the 'add a new payment' button $(button).attr('disabled', false); @@ -118,10 +122,8 @@ odoo.define('payment.payment_form', function (require) { self.displayError( _t('Server Error'), - _t("We are not able to add your payment method at the moment.
") + - "" +
- (core.debug ? (data.data.message.replace(/\n/g, "
")): '') +
- "
We are not able to redirect you to the payment form.
") + _t("We are not able to redirect you to the payment form.") ); } }).fail(function (message, data) { self.displayError( _t('Server Error'), - _t("We are not able to redirect you to the payment form.
") + - "" +
- (core.debug ? (data.data.message.replace(/\n/g, "
")): '') +
- "
We're unable to process your payment.
") + _t("We're unable to process your payment.") ); } } @@ -187,7 +187,7 @@ odoo.define('payment.payment_form', function (require) { else { this.displayError( _t('No payment method selected'), - _t('Please select a payment method.
') + _t('Please select a payment method.') ); } }, @@ -209,25 +209,31 @@ odoo.define('payment.payment_form', function (require) { var inputs_form = $('input', acquirer_form); var form_data = this.getFormData(inputs_form); var ds = $('input[name="data_set"]', acquirer_form)[0]; - var empty_inputs = false; - + var wrong_input = false; + inputs_form.toArray().forEach(function (element) { - if (element.dataset.isRequired) { - if (element.value.length === 0) { + //skip the check of non visible inputs + if ($(element).attr('type') == 'hidden') { + return true; + } + $(element).closest('div.form-group').removeClass('has-error'); + $(element).siblings( ".o_invalid_field" ).remove(); + //force check of forms validity (useful for Firefox that refill forms automatically on f5) + $(element).trigger("focusout"); + if (element.dataset.isRequired && element.value.length === 0) { $(element).closest('div.form-group').addClass('has-error'); - empty_inputs = true; - } - else { - $(element).closest('div.form-group').removeClass('has-error'); - } + var message = 'Please fill all the inputs required.
') - ); + if (wrong_input) { return; } // We add a 'processing' icon into the 'add a new payment' button @@ -274,17 +280,15 @@ odoo.define('payment.payment_form', function (require) { self.displayError( _t('Server error'), - _t("We are not able to add your payment method at the moment.
") + - "" +
- (core.debug ? (data.data.message.replace(/\n/g, "
")): '') +
- "
Please select the option to add a new payment method.
') + _t('Please select the option to add a new payment method.') ); } }, @@ -308,7 +312,7 @@ odoo.define('payment.payment_form', function (require) { }, function () { self.displayError( _t('Server Error'), - _t("We are not able to delete your payment method at the moment.
") + _t("We are not able to delete your payment method at the moment.") ); }); }; @@ -322,7 +326,7 @@ odoo.define('payment.payment_form', function (require) { // if there's records linked to this payment method var content = ''; result[pm_id].forEach(function (sub) { - content += '' + _.str.escapeHTML(sub.name) + '
'; + content += ''; }); content = $('This card is currently linked to the following records:
') + content); @@ -343,7 +347,7 @@ odoo.define('payment.payment_form', function (require) { }, function (type, err) { self.displayError( _t('Server Error'), - _t("We are not able to delete your payment method at the moment.
") + (core.debug ? err.data.message : '') + _t("We are not able to delete your payment method at the moment.") + err.data.message ); }); }, @@ -391,12 +395,27 @@ odoo.define('payment.payment_form', function (require) { return $(element).data('acquirer-id'); }, displayError: function (title, message) { - return new Dialog(null, { - title: _t('Error: ') + title, - size: 'medium', - $content: message || "", - buttons: [ - {text: _t('Ok'), close: true}]}).open(); + var $checkedRadio = this.$('input[type="radio"]:checked'), + acquirerID = this.getAcquirerIdFromRadio($checkedRadio[0]), + $acquirerForm = this.$('#o_payment_add_token_acq_' + acquirerID); + + if ($checkedRadio.length === 0) { + return new Dialog(null, { + title: _t('Error: ') + _.str.escapeHTML(title), + size: 'medium', + $content: "" + (_.str.escapeHTML(message) || "") + "
" , + buttons: [ + {text: _t('Ok'), close: true}]}).open(); + } else { + // removed if exist error message + this.$('#payment_error').remove(); + var messageResult = '