@hellotext/hellotext 2.5.6 → 2.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -26
- package/dist/hellotext.js +1 -1
- package/dist/hellotext.js.LICENSE.txt +1 -1
- package/index.d.ts +15 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +26 -46
- package/lib/api/index.js +28 -49
- package/lib/api/push/identities.cjs +43 -0
- package/lib/api/push/identities.js +35 -0
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +16 -0
- package/lib/core/configuration/push.js +10 -0
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +62 -75
- package/lib/core/configuration.js +61 -75
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +186 -211
- package/lib/hellotext.js +189 -236
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +115 -152
- package/lib/models/business.js +118 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/index.cjs +7 -0
- package/lib/models/index.js +1 -0
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +345 -0
- package/lib/models/push.js +339 -0
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +2 -10
- package/src/api/index.js +5 -0
- package/src/api/push/identities.js +42 -0
- package/src/core/configuration/push.js +12 -0
- package/src/core/configuration.js +5 -0
- package/src/hellotext.js +15 -1
- package/src/index.bundle.js +0 -1
- package/src/models/business.js +1 -0
- package/src/models/index.js +1 -0
- package/src/models/push.js +397 -0
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
|
@@ -10,135 +10,96 @@ var _models = require("../models");
|
|
|
10
10
|
var _forms = _interopRequireDefault(require("../api/forms"));
|
|
11
11
|
var _core = require("../core");
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
26
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
|
-
let _default = /*#__PURE__*/function (_Controller) {
|
|
28
|
-
_inherits(_default, _Controller);
|
|
29
|
-
var _super = _createSuper(_default);
|
|
30
|
-
function _default() {
|
|
31
|
-
_classCallCheck(this, _default);
|
|
32
|
-
return _super.apply(this, arguments);
|
|
13
|
+
class _default extends _stimulus.Controller {
|
|
14
|
+
static values = {
|
|
15
|
+
data: Object,
|
|
16
|
+
step: {
|
|
17
|
+
type: Number,
|
|
18
|
+
default: 1
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
static targets = ['inputContainer', 'input', 'button', 'otpContainer'];
|
|
22
|
+
initialize() {
|
|
23
|
+
this.form = new _models.Form(this.dataValue, this.element);
|
|
33
24
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
25
|
+
connect() {
|
|
26
|
+
super.connect();
|
|
27
|
+
this.element.addEventListener('submit', this.submit.bind(this));
|
|
28
|
+
if (document.activeElement.tagName !== 'INPUT') {
|
|
29
|
+
this.inputTargets[0].focus();
|
|
38
30
|
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (document.activeElement.tagName !== 'INPUT') {
|
|
45
|
-
this.inputTargets[0].focus();
|
|
46
|
-
}
|
|
31
|
+
}
|
|
32
|
+
async submit(e) {
|
|
33
|
+
e.preventDefault();
|
|
34
|
+
if (this.invalid) {
|
|
35
|
+
return this.showErrorMessages();
|
|
47
36
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
parameter
|
|
66
|
-
} = error;
|
|
67
|
-
const input = this.inputTargets.find(input => input.name === parameter);
|
|
68
|
-
input.setCustomValidity(_hellotext.default.business.locale.errors[type]);
|
|
37
|
+
this.clearErrorMessages();
|
|
38
|
+
this.formData = Object.fromEntries(new FormData(this.element));
|
|
39
|
+
this.buttonTarget.disabled = true;
|
|
40
|
+
const response = await _forms.default.submit(this.form.id, this.formData);
|
|
41
|
+
this.buttonTarget.disabled = false;
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
if (response.failed) {
|
|
44
|
+
data.errors.forEach(error => {
|
|
45
|
+
const {
|
|
46
|
+
type,
|
|
47
|
+
parameter
|
|
48
|
+
} = error;
|
|
49
|
+
const input = this.inputTargets.find(input => input.name === parameter);
|
|
50
|
+
input.setCustomValidity(_hellotext.default.business.locale.errors[type]);
|
|
51
|
+
input.reportValidity();
|
|
52
|
+
input.addEventListener('input', () => {
|
|
53
|
+
input.setCustomValidity('');
|
|
69
54
|
input.reportValidity();
|
|
70
|
-
input.addEventListener('input', () => {
|
|
71
|
-
input.setCustomValidity('');
|
|
72
|
-
input.reportValidity();
|
|
73
|
-
});
|
|
74
55
|
});
|
|
75
|
-
return this.showErrorMessages();
|
|
76
|
-
}
|
|
77
|
-
this.buttonTarget.style.display = 'none';
|
|
78
|
-
this.element.querySelectorAll('input').forEach(input => input.disabled = true);
|
|
79
|
-
this.completed();
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "completed",
|
|
83
|
-
value: function completed() {
|
|
84
|
-
this.form.markAsCompleted(this.formData);
|
|
85
|
-
if (!_core.Configuration.forms.shouldShowSuccessMessage) {
|
|
86
|
-
return this.element.remove();
|
|
87
|
-
}
|
|
88
|
-
if (typeof _core.Configuration.forms.successMessage === 'string') {
|
|
89
|
-
this.element.innerHTML = _core.Configuration.forms.successMessage;
|
|
90
|
-
} else {
|
|
91
|
-
this.element.innerHTML = _hellotext.default.business.locale.forms[this.form.localeAuthKey];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// private
|
|
96
|
-
}, {
|
|
97
|
-
key: "showErrorMessages",
|
|
98
|
-
value: function showErrorMessages() {
|
|
99
|
-
this.inputTargets.forEach(input => {
|
|
100
|
-
const errorsContainer = input.closest('article').querySelector('[data-error-container]');
|
|
101
|
-
if (input.validity.valid) {
|
|
102
|
-
errorsContainer.innerText = '';
|
|
103
|
-
} else {
|
|
104
|
-
errorsContainer.innerText = input.validationMessage;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: "clearErrorMessages",
|
|
110
|
-
value: function clearErrorMessages() {
|
|
111
|
-
this.inputTargets.forEach(input => {
|
|
112
|
-
input.setCustomValidity('');
|
|
113
|
-
input.closest('article').querySelector('[data-error-container]').innerText = '';
|
|
114
56
|
});
|
|
57
|
+
return this.showErrorMessages();
|
|
115
58
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
59
|
+
this.buttonTarget.style.display = 'none';
|
|
60
|
+
this.element.querySelectorAll('input').forEach(input => input.disabled = true);
|
|
61
|
+
this.completed();
|
|
62
|
+
}
|
|
63
|
+
completed() {
|
|
64
|
+
this.form.markAsCompleted(this.formData);
|
|
65
|
+
if (!_core.Configuration.forms.shouldShowSuccessMessage) {
|
|
66
|
+
return this.element.remove();
|
|
122
67
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
68
|
+
if (typeof _core.Configuration.forms.successMessage === 'string') {
|
|
69
|
+
this.element.innerHTML = _core.Configuration.forms.successMessage;
|
|
70
|
+
} else {
|
|
71
|
+
this.element.innerHTML = _hellotext.default.business.locale.forms[this.form.localeAuthKey];
|
|
127
72
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// private
|
|
76
|
+
|
|
77
|
+
showErrorMessages() {
|
|
78
|
+
this.inputTargets.forEach(input => {
|
|
79
|
+
const errorsContainer = input.closest('article').querySelector('[data-error-container]');
|
|
80
|
+
if (input.validity.valid) {
|
|
81
|
+
errorsContainer.innerText = '';
|
|
82
|
+
} else {
|
|
83
|
+
errorsContainer.innerText = input.validationMessage;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
clearErrorMessages() {
|
|
88
|
+
this.inputTargets.forEach(input => {
|
|
89
|
+
input.setCustomValidity('');
|
|
90
|
+
input.closest('article').querySelector('[data-error-container]').innerText = '';
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
inputTargetConnected(target) {
|
|
94
|
+
if (target.getAttribute('data-default-value')) {
|
|
95
|
+
target.value = target.getAttribute('data-default-value');
|
|
132
96
|
}
|
|
133
|
-
}]);
|
|
134
|
-
return _default;
|
|
135
|
-
}(_stimulus.Controller);
|
|
136
|
-
exports.default = _default;
|
|
137
|
-
_default.values = {
|
|
138
|
-
data: Object,
|
|
139
|
-
step: {
|
|
140
|
-
type: Number,
|
|
141
|
-
default: 1
|
|
142
97
|
}
|
|
143
|
-
|
|
144
|
-
|
|
98
|
+
get requiredInputs() {
|
|
99
|
+
return this.inputTargets.filter(input => input.required);
|
|
100
|
+
}
|
|
101
|
+
get invalid() {
|
|
102
|
+
return !this.element.checkValidity();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.default = _default;
|
|
@@ -1,145 +1,97 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
2
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
3
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
5
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
6
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
7
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
8
|
-
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
9
|
-
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
10
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
11
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
13
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
14
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
16
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
17
1
|
import { Controller } from '@hotwired/stimulus';
|
|
18
2
|
import Hellotext from '../hellotext';
|
|
19
3
|
import { Form } from '../models';
|
|
20
4
|
import FormsAPI from '../api/forms';
|
|
21
5
|
import { Configuration } from '../core';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
6
|
+
export default class extends Controller {
|
|
7
|
+
static values = {
|
|
8
|
+
data: Object,
|
|
9
|
+
step: {
|
|
10
|
+
type: Number,
|
|
11
|
+
default: 1
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
static targets = ['inputContainer', 'input', 'button', 'otpContainer'];
|
|
15
|
+
initialize() {
|
|
16
|
+
this.form = new Form(this.dataValue, this.element);
|
|
28
17
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
connect() {
|
|
19
|
+
super.connect();
|
|
20
|
+
this.element.addEventListener('submit', this.submit.bind(this));
|
|
21
|
+
if (document.activeElement.tagName !== 'INPUT') {
|
|
22
|
+
this.inputTargets[0].focus();
|
|
33
23
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (document.activeElement.tagName !== 'INPUT') {
|
|
40
|
-
this.inputTargets[0].focus();
|
|
41
|
-
}
|
|
24
|
+
}
|
|
25
|
+
async submit(e) {
|
|
26
|
+
e.preventDefault();
|
|
27
|
+
if (this.invalid) {
|
|
28
|
+
return this.showErrorMessages();
|
|
42
29
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} = error;
|
|
63
|
-
var input = this.inputTargets.find(input => input.name === parameter);
|
|
64
|
-
input.setCustomValidity(Hellotext.business.locale.errors[type]);
|
|
65
|
-
input.reportValidity();
|
|
66
|
-
input.addEventListener('input', () => {
|
|
67
|
-
input.setCustomValidity('');
|
|
68
|
-
input.reportValidity();
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
return this.showErrorMessages();
|
|
72
|
-
}
|
|
73
|
-
this.buttonTarget.style.display = 'none';
|
|
74
|
-
this.element.querySelectorAll('input').forEach(input => input.disabled = true);
|
|
75
|
-
this.completed();
|
|
30
|
+
this.clearErrorMessages();
|
|
31
|
+
this.formData = Object.fromEntries(new FormData(this.element));
|
|
32
|
+
this.buttonTarget.disabled = true;
|
|
33
|
+
const response = await FormsAPI.submit(this.form.id, this.formData);
|
|
34
|
+
this.buttonTarget.disabled = false;
|
|
35
|
+
const data = await response.json();
|
|
36
|
+
if (response.failed) {
|
|
37
|
+
data.errors.forEach(error => {
|
|
38
|
+
const {
|
|
39
|
+
type,
|
|
40
|
+
parameter
|
|
41
|
+
} = error;
|
|
42
|
+
const input = this.inputTargets.find(input => input.name === parameter);
|
|
43
|
+
input.setCustomValidity(Hellotext.business.locale.errors[type]);
|
|
44
|
+
input.reportValidity();
|
|
45
|
+
input.addEventListener('input', () => {
|
|
46
|
+
input.setCustomValidity('');
|
|
47
|
+
input.reportValidity();
|
|
48
|
+
});
|
|
76
49
|
});
|
|
77
|
-
|
|
78
|
-
return _submit.apply(this, arguments);
|
|
79
|
-
}
|
|
80
|
-
return submit;
|
|
81
|
-
}()
|
|
82
|
-
}, {
|
|
83
|
-
key: "completed",
|
|
84
|
-
value: function completed() {
|
|
85
|
-
this.form.markAsCompleted(this.formData);
|
|
86
|
-
if (!Configuration.forms.shouldShowSuccessMessage) {
|
|
87
|
-
return this.element.remove();
|
|
88
|
-
}
|
|
89
|
-
if (typeof Configuration.forms.successMessage === 'string') {
|
|
90
|
-
this.element.innerHTML = Configuration.forms.successMessage;
|
|
91
|
-
} else {
|
|
92
|
-
this.element.innerHTML = Hellotext.business.locale.forms[this.form.localeAuthKey];
|
|
93
|
-
}
|
|
50
|
+
return this.showErrorMessages();
|
|
94
51
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
errorsContainer.innerText = '';
|
|
104
|
-
} else {
|
|
105
|
-
errorsContainer.innerText = input.validationMessage;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
52
|
+
this.buttonTarget.style.display = 'none';
|
|
53
|
+
this.element.querySelectorAll('input').forEach(input => input.disabled = true);
|
|
54
|
+
this.completed();
|
|
55
|
+
}
|
|
56
|
+
completed() {
|
|
57
|
+
this.form.markAsCompleted(this.formData);
|
|
58
|
+
if (!Configuration.forms.shouldShowSuccessMessage) {
|
|
59
|
+
return this.element.remove();
|
|
108
60
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.
|
|
113
|
-
input.setCustomValidity('');
|
|
114
|
-
input.closest('article').querySelector('[data-error-container]').innerText = '';
|
|
115
|
-
});
|
|
61
|
+
if (typeof Configuration.forms.successMessage === 'string') {
|
|
62
|
+
this.element.innerHTML = Configuration.forms.successMessage;
|
|
63
|
+
} else {
|
|
64
|
+
this.element.innerHTML = Hellotext.business.locale.forms[this.form.localeAuthKey];
|
|
116
65
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// private
|
|
69
|
+
|
|
70
|
+
showErrorMessages() {
|
|
71
|
+
this.inputTargets.forEach(input => {
|
|
72
|
+
const errorsContainer = input.closest('article').querySelector('[data-error-container]');
|
|
73
|
+
if (input.validity.valid) {
|
|
74
|
+
errorsContainer.innerText = '';
|
|
75
|
+
} else {
|
|
76
|
+
errorsContainer.innerText = input.validationMessage;
|
|
122
77
|
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
clearErrorMessages() {
|
|
81
|
+
this.inputTargets.forEach(input => {
|
|
82
|
+
input.setCustomValidity('');
|
|
83
|
+
input.closest('article').querySelector('[data-error-container]').innerText = '';
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
inputTargetConnected(target) {
|
|
87
|
+
if (target.getAttribute('data-default-value')) {
|
|
88
|
+
target.value = target.getAttribute('data-default-value');
|
|
123
89
|
}
|
|
124
|
-
}, {
|
|
125
|
-
key: "requiredInputs",
|
|
126
|
-
get: function get() {
|
|
127
|
-
return this.inputTargets.filter(input => input.required);
|
|
128
|
-
}
|
|
129
|
-
}, {
|
|
130
|
-
key: "invalid",
|
|
131
|
-
get: function get() {
|
|
132
|
-
return !this.element.checkValidity();
|
|
133
|
-
}
|
|
134
|
-
}]);
|
|
135
|
-
return _default;
|
|
136
|
-
}(Controller);
|
|
137
|
-
_default.values = {
|
|
138
|
-
data: Object,
|
|
139
|
-
step: {
|
|
140
|
-
type: Number,
|
|
141
|
-
default: 1
|
|
142
90
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
91
|
+
get requiredInputs() {
|
|
92
|
+
return this.inputTargets.filter(input => input.required);
|
|
93
|
+
}
|
|
94
|
+
get invalid() {
|
|
95
|
+
return !this.element.checkValidity();
|
|
96
|
+
}
|
|
97
|
+
}
|