@subiz/widget-v4 4.1.137 → 4.1.139
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/assets/less/form-page.less +11 -3
- package/compiled_src/form/Form.js +32 -8
- package/compiled_src/form/FormPage.js +14 -6
- package/compiled_src/form.js +9 -1
- package/package.json +1 -1
- package/src/form/Form.js +33 -9
- package/src/form/FormPage.js +8 -5
- package/src/form.js +25 -10
|
@@ -41,9 +41,6 @@ body div#sbz92 {
|
|
|
41
41
|
@import 'base.less';
|
|
42
42
|
|
|
43
43
|
* {
|
|
44
|
-
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
|
45
|
-
-webkit-tap-highlight-color: transparent;
|
|
46
|
-
|
|
47
44
|
font-family: @font-family-sans-serif;
|
|
48
45
|
font-size: @font-size-base;
|
|
49
46
|
|
|
@@ -306,5 +303,16 @@ body div#sbz92 {
|
|
|
306
303
|
height: 40px;
|
|
307
304
|
}
|
|
308
305
|
|
|
306
|
+
.form-page-preview-noti {
|
|
307
|
+
background: #fef7e0;
|
|
308
|
+
text-align: center;
|
|
309
|
+
border-radius: 6px;
|
|
310
|
+
margin-top: 10px;
|
|
311
|
+
margin-left: 15px;
|
|
312
|
+
margin-right: 15px;
|
|
313
|
+
padding: 8px 12px;
|
|
314
|
+
color: #202122;
|
|
315
|
+
}
|
|
316
|
+
|
|
309
317
|
@import 'form.less';
|
|
310
318
|
}
|
|
@@ -63,7 +63,7 @@ class Form2 extends _common.Com {
|
|
|
63
63
|
class: "label"
|
|
64
64
|
}, com.label, " ", com.is_required && (0, _preact.h)("span", {
|
|
65
65
|
class: "red"
|
|
66
|
-
}, "*")), com.input_type === 'text' && this.renderFieldTextInput(com, idx), com.input_type === '
|
|
66
|
+
}, "*")), com.input_type === 'text' && this.renderFieldTextInput(com, idx), com.input_type === 'textarea' && this.renderFieldTextareaInput(com, idx), com.input_type === 'date' && this.renderFieldDateInput(com, idx), com.input_type === 'radio' && this.renderFieldRadioInput(com, idx), com.input_type === 'checkbox' && this.renderFieldCheckboxInput(com, idx), (com.input_type === 'dropdown' || com.input_type === 'select') && this.renderFieldDropdownInput(com, idx), errorMsg && (0, _preact.h)("div", {
|
|
67
67
|
class: "form-control--valid-input--error"
|
|
68
68
|
}, errorMsg));
|
|
69
69
|
});
|
|
@@ -195,18 +195,42 @@ class Form2 extends _common.Com {
|
|
|
195
195
|
let components = _index.default.get(this.props.formSetting, 'components') || [];
|
|
196
196
|
_index.default.each(components, com => {
|
|
197
197
|
if (com.type === 'input') {
|
|
198
|
+
let val = _index.default.find(this.props.submission.values, f => f.key === com.key) || {};
|
|
199
|
+
val = val.value || '""';
|
|
200
|
+
val = _index.default.parseJSON(val);
|
|
198
201
|
if (com.is_required) {
|
|
199
|
-
let
|
|
200
|
-
val
|
|
201
|
-
|
|
202
|
-
if (
|
|
202
|
+
let isEmpty = false;
|
|
203
|
+
if (typeof val === 'string' && !val.trim()) isEmpty = true;
|
|
204
|
+
if (Array.isArray(val) && val.length === 0) isEmpty = true;
|
|
205
|
+
if (isEmpty) {
|
|
203
206
|
result = false;
|
|
204
207
|
errors[com.key] = this.props.t('cannot_be_empty');
|
|
205
|
-
|
|
208
|
+
ref = `${com.key}_input`;
|
|
206
209
|
}
|
|
207
|
-
|
|
210
|
+
}
|
|
211
|
+
if (com.validation && !Array.isArray(val)) {
|
|
212
|
+
let isInvalid = false;
|
|
213
|
+
let validationText = '';
|
|
214
|
+
if (com.validation === 'email' && !_index.default.isEmail(val)) {
|
|
215
|
+
validationText = 'Email';
|
|
216
|
+
isInvalid = true;
|
|
217
|
+
}
|
|
218
|
+
if (com.validation === 'phone' && !_index.default.isPhone(val)) {
|
|
219
|
+
validationText = this.props.t('phn');
|
|
220
|
+
isInvalid = true;
|
|
221
|
+
}
|
|
222
|
+
if (com.validation === 'number' && !_index.default.isNumber(val)) {
|
|
223
|
+
validationText = this.props.t('number');
|
|
224
|
+
isInvalid = true;
|
|
225
|
+
}
|
|
226
|
+
if (com.validation === 'url' && !_index.default.isURL(val)) {
|
|
227
|
+
isInvalid = true;
|
|
228
|
+
validationText = 'URL';
|
|
229
|
+
}
|
|
230
|
+
if (isInvalid) {
|
|
208
231
|
result = false;
|
|
209
|
-
errors[com.key] = this.props.t('
|
|
232
|
+
errors[com.key] = this.props.t('format_is_invalid') + ' ' + validationText;
|
|
233
|
+
ref = `${com.key}_input`;
|
|
210
234
|
}
|
|
211
235
|
}
|
|
212
236
|
}
|
|
@@ -27,7 +27,6 @@ class FormPage extends _common.Com {
|
|
|
27
27
|
if (document.fonts.check('normal 16px ' + fonts[i])) {
|
|
28
28
|
ready[fonts[i]] = true;
|
|
29
29
|
}
|
|
30
|
-
console.log('ready', ready, Object.keys(ready), fonts.length, Object.keys(ready) === fonts.length);
|
|
31
30
|
if (_index.default.size(Object.keys(ready)) === fonts.length) {
|
|
32
31
|
return;
|
|
33
32
|
}
|
|
@@ -79,12 +78,16 @@ class FormPage extends _common.Com {
|
|
|
79
78
|
let chatbox = _index.default.find(this.props.store.matchPlugin(), plugin => plugin.type === 'chatbox') || {};
|
|
80
79
|
chatbox = chatbox.chatbox || {};
|
|
81
80
|
if (this.props.previewJson) {
|
|
81
|
+
this.setState({
|
|
82
|
+
loading: true
|
|
83
|
+
});
|
|
82
84
|
let json = atob(this.props.previewJson);
|
|
83
85
|
json = decodeURIComponent(json);
|
|
84
86
|
json = _index.default.parseJSON(json);
|
|
85
87
|
await this.insertCss(chatbox, json);
|
|
86
88
|
this.setState({
|
|
87
|
-
formSetting: json
|
|
89
|
+
formSetting: json,
|
|
90
|
+
loading: false
|
|
88
91
|
});
|
|
89
92
|
return;
|
|
90
93
|
}
|
|
@@ -172,14 +175,16 @@ class FormPage extends _common.Com {
|
|
|
172
175
|
} = this.state;
|
|
173
176
|
if (loading && !loadError) {
|
|
174
177
|
return (0, _preact.h)("div", {
|
|
175
|
-
class: "h-full w-full d-flex justify-content-center align-items-center"
|
|
178
|
+
class: "h-full w-full d-flex justify-content-center align-items-center",
|
|
179
|
+
key: "loading"
|
|
176
180
|
}, (0, _preact.h)("div", {
|
|
177
181
|
class: "text-muted text-xl"
|
|
178
182
|
}, this.props.t('loading_data'), " ..."));
|
|
179
183
|
}
|
|
180
184
|
if (loadError) {
|
|
181
185
|
return (0, _preact.h)("div", {
|
|
182
|
-
class: "h-full w-full d-flex justify-content-center align-items-center"
|
|
186
|
+
class: "h-full w-full d-flex justify-content-center align-items-center",
|
|
187
|
+
key: "error"
|
|
183
188
|
}, (0, _preact.h)("div", {
|
|
184
189
|
class: "text-center"
|
|
185
190
|
}, (0, _preact.h)("div", {
|
|
@@ -193,8 +198,11 @@ class FormPage extends _common.Com {
|
|
|
193
198
|
}
|
|
194
199
|
let brandLogo = _index.default.get(formSetting, 'logo.url');
|
|
195
200
|
return (0, _preact.h)("div", {
|
|
196
|
-
class: "form-page-body"
|
|
197
|
-
|
|
201
|
+
class: "form-page-body",
|
|
202
|
+
key: "form"
|
|
203
|
+
}, this.props.previewJson && (0, _preact.h)("div", {
|
|
204
|
+
class: "form-page-preview-noti"
|
|
205
|
+
}, 'Form ở trạng thái xem thử, không ghi nhận phản hồi'), (0, _preact.h)("div", {
|
|
198
206
|
class: "form-page"
|
|
199
207
|
}, (0, _preact.h)("div", {
|
|
200
208
|
class: "form-page-logo-wrapper"
|
package/compiled_src/form.js
CHANGED
|
@@ -18,13 +18,21 @@ async function renderForm(form, chatbox, $div) {
|
|
|
18
18
|
(0, _preact.render)((0, _preact.h)("div", null, "Loading"), $div);
|
|
19
19
|
return;
|
|
20
20
|
}
|
|
21
|
+
const LANG = {
|
|
22
|
+
no_select: 'Chưa chọn',
|
|
23
|
+
cannot_be_empty: 'không thể để trống',
|
|
24
|
+
you_have_submitted_info_successfully: 'Form được gửi thành công',
|
|
25
|
+
no_info_input: 'Chưa nhập'
|
|
26
|
+
};
|
|
21
27
|
(0, _preact.render)((0, _preact.h)(_Form.default, {
|
|
22
28
|
mode: "attachment",
|
|
29
|
+
onChangeFormValues: () => {},
|
|
30
|
+
onSubmit: () => {},
|
|
23
31
|
formSetting: form,
|
|
24
32
|
submission: {
|
|
25
33
|
values: []
|
|
26
34
|
},
|
|
27
|
-
t:
|
|
35
|
+
t: key => LANG[key]
|
|
28
36
|
}), $div);
|
|
29
37
|
}
|
|
30
38
|
async function initCss(chatbox) {
|
package/package.json
CHANGED
package/src/form/Form.js
CHANGED
|
@@ -66,11 +66,11 @@ export default class Form2 extends Com {
|
|
|
66
66
|
{com.label} {com.is_required && <span class='red'>*</span>}
|
|
67
67
|
</label>
|
|
68
68
|
{com.input_type === 'text' && this.renderFieldTextInput(com, idx)}
|
|
69
|
-
{com.input_type === '
|
|
69
|
+
{com.input_type === 'textarea' && this.renderFieldTextareaInput(com, idx)}
|
|
70
70
|
{com.input_type === 'date' && this.renderFieldDateInput(com, idx)}
|
|
71
71
|
{com.input_type === 'radio' && this.renderFieldRadioInput(com, idx)}
|
|
72
72
|
{com.input_type === 'checkbox' && this.renderFieldCheckboxInput(com, idx)}
|
|
73
|
-
{com.input_type === 'dropdown' && this.renderFieldDropdownInput(com, idx)}
|
|
73
|
+
{(com.input_type === 'dropdown' || com.input_type === 'select') && this.renderFieldDropdownInput(com, idx)}
|
|
74
74
|
{errorMsg && <div class='form-control--valid-input--error'>{errorMsg}</div>}
|
|
75
75
|
</div>
|
|
76
76
|
)
|
|
@@ -220,18 +220,42 @@ export default class Form2 extends Com {
|
|
|
220
220
|
let components = sb.get(this.props.formSetting, 'components') || []
|
|
221
221
|
sb.each(components, (com) => {
|
|
222
222
|
if (com.type === 'input') {
|
|
223
|
+
let val = sb.find(this.props.submission.values, (f) => f.key === com.key) || {}
|
|
224
|
+
val = val.value || '""'
|
|
225
|
+
val = sb.parseJSON(val)
|
|
223
226
|
if (com.is_required) {
|
|
224
|
-
let
|
|
225
|
-
val
|
|
226
|
-
|
|
227
|
-
if (
|
|
227
|
+
let isEmpty = false
|
|
228
|
+
if (typeof val === 'string' && !val.trim()) isEmpty = true
|
|
229
|
+
if (Array.isArray(val) && val.length === 0) isEmpty = true
|
|
230
|
+
if (isEmpty) {
|
|
228
231
|
result = false
|
|
229
232
|
errors[com.key] = this.props.t('cannot_be_empty')
|
|
230
|
-
|
|
233
|
+
ref = `${com.key}_input`
|
|
231
234
|
}
|
|
232
|
-
|
|
235
|
+
}
|
|
236
|
+
if (com.validation && !Array.isArray(val)) {
|
|
237
|
+
let isInvalid = false
|
|
238
|
+
let validationText = ''
|
|
239
|
+
if (com.validation === 'email' && !sb.isEmail(val)) {
|
|
240
|
+
validationText = 'Email'
|
|
241
|
+
isInvalid = true
|
|
242
|
+
}
|
|
243
|
+
if (com.validation === 'phone' && !sb.isPhone(val)) {
|
|
244
|
+
validationText = this.props.t('phn')
|
|
245
|
+
isInvalid = true
|
|
246
|
+
}
|
|
247
|
+
if (com.validation === 'number' && !sb.isNumber(val)) {
|
|
248
|
+
validationText = this.props.t('number')
|
|
249
|
+
isInvalid = true
|
|
250
|
+
}
|
|
251
|
+
if (com.validation === 'url' && !sb.isURL(val)) {
|
|
252
|
+
isInvalid = true
|
|
253
|
+
validationText = 'URL'
|
|
254
|
+
}
|
|
255
|
+
if (isInvalid) {
|
|
233
256
|
result = false
|
|
234
|
-
errors[com.key] = this.props.t('
|
|
257
|
+
errors[com.key] = this.props.t('format_is_invalid') + ' ' + validationText
|
|
258
|
+
ref = `${com.key}_input`
|
|
235
259
|
}
|
|
236
260
|
}
|
|
237
261
|
}
|
package/src/form/FormPage.js
CHANGED
|
@@ -35,7 +35,6 @@ export default class FormPage extends Com {
|
|
|
35
35
|
if (document.fonts.check('normal 16px ' + fonts[i])) {
|
|
36
36
|
ready[fonts[i]] = true
|
|
37
37
|
}
|
|
38
|
-
console.log('ready', ready, Object.keys(ready), fonts.length, Object.keys(ready) === fonts.length)
|
|
39
38
|
if (sb.size(Object.keys(ready)) === fonts.length) {
|
|
40
39
|
return
|
|
41
40
|
}
|
|
@@ -95,11 +94,12 @@ export default class FormPage extends Com {
|
|
|
95
94
|
chatbox = chatbox.chatbox || {}
|
|
96
95
|
|
|
97
96
|
if (this.props.previewJson) {
|
|
97
|
+
this.setState({loading: true})
|
|
98
98
|
let json = atob(this.props.previewJson)
|
|
99
99
|
json = decodeURIComponent(json)
|
|
100
100
|
json = sb.parseJSON(json)
|
|
101
101
|
await this.insertCss(chatbox, json)
|
|
102
|
-
this.setState({formSetting: json})
|
|
102
|
+
this.setState({formSetting: json, loading: false})
|
|
103
103
|
return
|
|
104
104
|
}
|
|
105
105
|
if (this.state.loading) return
|
|
@@ -148,14 +148,14 @@ export default class FormPage extends Com {
|
|
|
148
148
|
const {formSetting, loading, loadError, submission, errorMessage, isSubmited, submiting} = this.state
|
|
149
149
|
if (loading && !loadError) {
|
|
150
150
|
return (
|
|
151
|
-
<div class='h-full w-full d-flex justify-content-center align-items-center'>
|
|
151
|
+
<div class='h-full w-full d-flex justify-content-center align-items-center' key='loading'>
|
|
152
152
|
<div class='text-muted text-xl'>{this.props.t('loading_data')} ...</div>
|
|
153
153
|
</div>
|
|
154
154
|
)
|
|
155
155
|
}
|
|
156
156
|
if (loadError) {
|
|
157
157
|
return (
|
|
158
|
-
<div class='h-full w-full d-flex justify-content-center align-items-center'>
|
|
158
|
+
<div class='h-full w-full d-flex justify-content-center align-items-center' key='error'>
|
|
159
159
|
<div class='text-center'>
|
|
160
160
|
<div class='text-danger text-lg mb-2'>{this.props.t('error_occurs_when_load_data')}</div>
|
|
161
161
|
<br />
|
|
@@ -169,7 +169,10 @@ export default class FormPage extends Com {
|
|
|
169
169
|
|
|
170
170
|
let brandLogo = sb.get(formSetting, 'logo.url')
|
|
171
171
|
return (
|
|
172
|
-
<div class='form-page-body'>
|
|
172
|
+
<div class='form-page-body' key='form'>
|
|
173
|
+
{this.props.previewJson && (
|
|
174
|
+
<div class='form-page-preview-noti'>{'Form ở trạng thái xem thử, không ghi nhận phản hồi'}</div>
|
|
175
|
+
)}
|
|
173
176
|
<div class='form-page'>
|
|
174
177
|
<div class='form-page-logo-wrapper'>
|
|
175
178
|
<a href={formSetting.brand_url || 'javascript:;'}>
|
package/src/form.js
CHANGED
|
@@ -5,18 +5,33 @@ import sb from './util/index.js'
|
|
|
5
5
|
|
|
6
6
|
let loadStatus = ''
|
|
7
7
|
export default async function renderForm(form, chatbox, $div) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
initCss(chatbox)
|
|
9
|
+
if (loadStatus !== 'done') {
|
|
10
|
+
render(<div>Loading</div>, $div)
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
const LANG = {
|
|
14
|
+
no_select: 'Chưa chọn',
|
|
15
|
+
cannot_be_empty: 'không thể để trống',
|
|
16
|
+
you_have_submitted_info_successfully: 'Form được gửi thành công',
|
|
17
|
+
no_info_input: 'Chưa nhập',
|
|
18
|
+
}
|
|
19
|
+
render(
|
|
20
|
+
<Form
|
|
21
|
+
mode='attachment'
|
|
22
|
+
onChangeFormValues={() => {}}
|
|
23
|
+
onSubmit={() => {}}
|
|
24
|
+
formSetting={form}
|
|
25
|
+
submission={{values: []}}
|
|
26
|
+
t={(key) => LANG[key]}
|
|
27
|
+
/>,
|
|
28
|
+
$div,
|
|
29
|
+
)
|
|
15
30
|
}
|
|
16
31
|
|
|
17
32
|
async function initCss(chatbox) {
|
|
18
|
-
|
|
19
|
-
|
|
33
|
+
if (loadStatus) return
|
|
34
|
+
loadStatus = 'loadiing'
|
|
20
35
|
let css = (await promiseMainCSS).default.default.toString()
|
|
21
36
|
let outcss = sb.replaceCssVariable(css, chatbox)
|
|
22
37
|
|
|
@@ -26,5 +41,5 @@ async function initCss(chatbox) {
|
|
|
26
41
|
$cssStyleDiv.id = 'subiz-style-for-form'
|
|
27
42
|
|
|
28
43
|
sb.setCss('form', $cssStyleDiv, outcss)
|
|
29
|
-
|
|
44
|
+
loadStatus = 'done'
|
|
30
45
|
}
|