zidan-select 2.3.0 → 2.4.0
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 +186 -72
- package/dist/file/plugin-file-core.css +8 -1
- package/dist/file/plugin-file-core.min.css +2 -2
- package/dist/file/plugin-file-theme.css +1 -1
- package/dist/file/plugin-file-theme.min.css +1 -1
- package/dist/file/zidan-file.d.ts +1 -1
- package/dist/file/zidan-file.js +94 -25
- package/dist/file/zidan-file.min.js +2 -2
- package/dist/plugin-core.css +109 -1
- package/dist/plugin-core.min.css +2 -2
- package/dist/plugin-theme.css +1 -1
- package/dist/plugin-theme.min.css +1 -1
- package/dist/select/plugin-select-core.css +1 -1
- package/dist/select/plugin-select-core.min.css +1 -1
- package/dist/select/plugin-select-theme.css +1 -1
- package/dist/select/plugin-select-theme.min.css +1 -1
- package/dist/select/zidan-select.d.ts +1 -1
- package/dist/select/zidan-select.js +233 -8
- package/dist/select/zidan-select.min.js +2 -2
- package/dist/zidan-form.js +383 -55
- package/dist/zidan-form.min.js +2 -2
- package/docs/build.md +66 -40
- package/docs/html-and-wordpress.md +20 -20
- package/docs/index.html +20 -8
- package/docs/options.md +76 -11
- package/docs/validation.md +8 -0
- package/package.json +6 -2
- package/plugin-core.css +109 -1
- package/plugin-theme.css +1 -1
- package/zidan-form.d.ts +28 -1
- package/zidan-form.js +383 -55
package/zidan-form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* ZidanForm v2.
|
|
2
|
+
* ZidanForm v2.4.0
|
|
3
3
|
* Zero-dependency form enhancement library: select / combobox / tags,
|
|
4
4
|
* checkboxes, switches, radio groups, file upload with drag & drop and
|
|
5
5
|
* upload progress, text / number / phone / date / range inputs and textarea.
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
})(typeof window !== 'undefined' ? window : this, function (global) {
|
|
33
33
|
'use strict';
|
|
34
34
|
|
|
35
|
-
var VERSION = '2.
|
|
35
|
+
var VERSION = '2.4.0';
|
|
36
36
|
|
|
37
37
|
// Loading the file twice (classic script + module wrapper, or two bundles)
|
|
38
38
|
// must not replace the classes and orphan the live instances.
|
|
@@ -582,6 +582,24 @@
|
|
|
582
582
|
return list.indexOf(candidate) === -1 ? fallback : candidate;
|
|
583
583
|
}
|
|
584
584
|
|
|
585
|
+
/* rangeTicks: JS array, JSON array, comma list or a tick count */
|
|
586
|
+
function parseRangeTicks(value) {
|
|
587
|
+
if (Array.isArray(value)) return value.slice();
|
|
588
|
+
if (typeof value === 'string') {
|
|
589
|
+
var raw = value.trim();
|
|
590
|
+
if (raw.charAt(0) === '[') {
|
|
591
|
+
try {
|
|
592
|
+
var parsed = JSON.parse(raw);
|
|
593
|
+
if (Array.isArray(parsed)) return parsed;
|
|
594
|
+
} catch (err) { /* fall back to the tick count */ }
|
|
595
|
+
} else if (raw.indexOf(',') !== -1) {
|
|
596
|
+
return raw.split(',').map(function (part) { return Number(part.trim()); })
|
|
597
|
+
.filter(function (number) { return isFinite(number); });
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return value;
|
|
601
|
+
}
|
|
602
|
+
|
|
585
603
|
/* theme/framework/layout resolution shared by every field and the select */
|
|
586
604
|
function resolveScope(node, options) {
|
|
587
605
|
var opts = options || {};
|
|
@@ -653,6 +671,17 @@
|
|
|
653
671
|
autoLoadMore: true,
|
|
654
672
|
cacheResults: true,
|
|
655
673
|
loadMoreText: 'Load more',
|
|
674
|
+
fetchUrl: null, // declarative AJAX: GET this endpoint instead of writing fetchOptions
|
|
675
|
+
fetchMethod: 'GET',
|
|
676
|
+
fetchQueryParam: 'q',
|
|
677
|
+
fetchPageParam: 'page', // 1-based page number sent with every request
|
|
678
|
+
fetchSkipParam: null, // when set, send skip = page * pageSize instead of fetchPageParam
|
|
679
|
+
fetchPageSizeParam: 'limit',
|
|
680
|
+
fetchItemsPath: null, // dot path to the array in the JSON body ('data.items')
|
|
681
|
+
fetchTotalPath: null, // dot path to the number of rows available
|
|
682
|
+
fetchHasMorePath: null, // dot path to a boolean
|
|
683
|
+
fetchHeaders: null,
|
|
684
|
+
fetchCredentials: 'same-origin',
|
|
656
685
|
/* tags */
|
|
657
686
|
maxTags: Infinity,
|
|
658
687
|
minTagLength: 1,
|
|
@@ -690,6 +719,112 @@
|
|
|
690
719
|
* ZidanSelect
|
|
691
720
|
* ------------------------------------------------------------------ */
|
|
692
721
|
|
|
722
|
+
/* ---------------- declarative AJAX (fetchUrl) ---------------- */
|
|
723
|
+
|
|
724
|
+
function readDotPath(source, path) {
|
|
725
|
+
if (!path) return undefined;
|
|
726
|
+
return String(path).split('.').reduce(function (node, key) {
|
|
727
|
+
return node === null || node === undefined ? undefined : node[key];
|
|
728
|
+
}, source);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
function firstRemoteArray(body) {
|
|
732
|
+
if (Array.isArray(body)) return body;
|
|
733
|
+
if (!body || typeof body !== 'object') return [];
|
|
734
|
+
var keys = ['items', 'data', 'results', 'options', 'rows', 'products', 'records'];
|
|
735
|
+
for (var i = 0; i < keys.length; i++) {
|
|
736
|
+
if (Array.isArray(body[keys[i]])) return body[keys[i]];
|
|
737
|
+
}
|
|
738
|
+
return [];
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/* Map common API shapes ({id,title}, {value,label}, plain strings) to select items. */
|
|
742
|
+
function remoteItem(raw) {
|
|
743
|
+
if (raw === null || raw === undefined) return null;
|
|
744
|
+
if (typeof raw !== 'object') {
|
|
745
|
+
var text = String(raw);
|
|
746
|
+
return { value: text, label: text };
|
|
747
|
+
}
|
|
748
|
+
var value = raw.value !== undefined ? raw.value
|
|
749
|
+
: raw.id !== undefined ? raw.id
|
|
750
|
+
: raw.slug !== undefined ? raw.slug
|
|
751
|
+
: raw.code !== undefined ? raw.code
|
|
752
|
+
: raw.key !== undefined ? raw.key : undefined;
|
|
753
|
+
var label = raw.label !== undefined ? raw.label
|
|
754
|
+
: raw.name !== undefined ? raw.name
|
|
755
|
+
: raw.title !== undefined ? raw.title
|
|
756
|
+
: raw.full_name !== undefined ? raw.full_name
|
|
757
|
+
: raw.text !== undefined ? raw.text : undefined;
|
|
758
|
+
if (label === undefined) label = value === undefined ? '' : value;
|
|
759
|
+
if (value === undefined) value = label;
|
|
760
|
+
return { value: value, label: label, disabled: !!raw.disabled };
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/*
|
|
764
|
+
* Turns fetchUrl + fetch* options into the same promise fetchOptions would return:
|
|
765
|
+
* { items, hasMore, total }. Honours AbortSignal and the paging context the
|
|
766
|
+
* select passes in, so caching, debounce and "Load more" work unchanged.
|
|
767
|
+
*/
|
|
768
|
+
function createRemoteFetcher(opts) {
|
|
769
|
+
return function (query, signal, context) {
|
|
770
|
+
if (typeof fetch !== 'function') {
|
|
771
|
+
return Promise.reject(new Error('This environment has no fetch().'));
|
|
772
|
+
}
|
|
773
|
+
var page = context && context.page ? context.page : 0;
|
|
774
|
+
var pageSize = opts.fetchPageSize > 0 ? opts.fetchPageSize : 0;
|
|
775
|
+
var url;
|
|
776
|
+
try {
|
|
777
|
+
url = new URL(opts.fetchUrl, (typeof location !== 'undefined' && location.href) || undefined);
|
|
778
|
+
} catch (error) {
|
|
779
|
+
return Promise.reject(new Error('Invalid fetchUrl: ' + opts.fetchUrl));
|
|
780
|
+
}
|
|
781
|
+
if (opts.fetchQueryParam) url.searchParams.set(opts.fetchQueryParam, query || '');
|
|
782
|
+
if (pageSize > 0 && opts.fetchPageSizeParam) {
|
|
783
|
+
url.searchParams.set(opts.fetchPageSizeParam, String(pageSize));
|
|
784
|
+
}
|
|
785
|
+
if (opts.fetchSkipParam) {
|
|
786
|
+
if (pageSize > 0) url.searchParams.set(opts.fetchSkipParam, String(page * pageSize));
|
|
787
|
+
} else if (opts.fetchPageParam) {
|
|
788
|
+
url.searchParams.set(opts.fetchPageParam, String(page + 1));
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
var headers = { Accept: 'application/json' };
|
|
792
|
+
if (opts.fetchHeaders && typeof opts.fetchHeaders === 'object') {
|
|
793
|
+
Object.keys(opts.fetchHeaders).forEach(function (key) {
|
|
794
|
+
headers[key] = opts.fetchHeaders[key];
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
return fetch(url.toString(), {
|
|
799
|
+
method: opts.fetchMethod || 'GET',
|
|
800
|
+
headers: headers,
|
|
801
|
+
signal: signal,
|
|
802
|
+
credentials: opts.fetchCredentials || 'same-origin'
|
|
803
|
+
}).then(function (response) {
|
|
804
|
+
if (!response.ok) {
|
|
805
|
+
throw new Error('Request failed (' + response.status + ' ' + (response.statusText || 'error') + ')');
|
|
806
|
+
}
|
|
807
|
+
return response.json();
|
|
808
|
+
}).then(function (body) {
|
|
809
|
+
var rows = opts.fetchItemsPath ? readDotPath(body, opts.fetchItemsPath) : firstRemoteArray(body);
|
|
810
|
+
if (!Array.isArray(rows)) rows = rows === undefined || rows === null ? [] : [rows];
|
|
811
|
+
var items = rows.map(remoteItem).filter(Boolean);
|
|
812
|
+
|
|
813
|
+
var hasMore;
|
|
814
|
+
if (opts.fetchHasMorePath) hasMore = !!readDotPath(body, opts.fetchHasMorePath);
|
|
815
|
+
var rawTotal = opts.fetchTotalPath ? readDotPath(body, opts.fetchTotalPath)
|
|
816
|
+
: (body && typeof body === 'object' ? body.total : undefined);
|
|
817
|
+
var total = rawTotal === undefined || rawTotal === null ? NaN : Number(rawTotal);
|
|
818
|
+
if (hasMore === undefined && isFinite(total) && pageSize > 0) {
|
|
819
|
+
hasMore = (page + 1) * pageSize < total;
|
|
820
|
+
}
|
|
821
|
+
if (hasMore === undefined) hasMore = pageSize > 0 && items.length >= pageSize;
|
|
822
|
+
|
|
823
|
+
return { items: items, hasMore: hasMore, total: isFinite(total) ? total : undefined };
|
|
824
|
+
});
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
|
|
693
828
|
function ZidanSelect(target, options) {
|
|
694
829
|
if (!(this instanceof ZidanSelect)) return new ZidanSelect(target, options);
|
|
695
830
|
if (!doc) throw new Error('ZidanSelect requires a DOM environment.');
|
|
@@ -810,6 +945,15 @@
|
|
|
810
945
|
merged.autoLoadMore = pick('autoLoadMore', readBoolAttr(d.zidanAutoLoadMore, DEFAULTS.autoLoadMore));
|
|
811
946
|
merged.cacheResults = pick('cacheResults', readBoolAttr(d.zidanCacheResults, DEFAULTS.cacheResults));
|
|
812
947
|
merged.loadMoreText = pick('loadMoreText', d.zidanLoadMoreText || DEFAULTS.loadMoreText);
|
|
948
|
+
merged.fetchUrl = pick('fetchUrl', d.zidanFetchUrl || null);
|
|
949
|
+
merged.fetchMethod = pick('fetchMethod', d.zidanFetchMethod || DEFAULTS.fetchMethod);
|
|
950
|
+
merged.fetchQueryParam = pick('fetchQueryParam', d.zidanFetchQueryParam !== undefined ? d.zidanFetchQueryParam : DEFAULTS.fetchQueryParam);
|
|
951
|
+
merged.fetchPageParam = pick('fetchPageParam', d.zidanFetchPageParam !== undefined ? d.zidanFetchPageParam : DEFAULTS.fetchPageParam);
|
|
952
|
+
merged.fetchSkipParam = pick('fetchSkipParam', d.zidanFetchSkipParam || null);
|
|
953
|
+
merged.fetchPageSizeParam = pick('fetchPageSizeParam', d.zidanFetchPageSizeParam !== undefined ? d.zidanFetchPageSizeParam : DEFAULTS.fetchPageSizeParam);
|
|
954
|
+
merged.fetchItemsPath = pick('fetchItemsPath', d.zidanFetchItemsPath || null);
|
|
955
|
+
merged.fetchTotalPath = pick('fetchTotalPath', d.zidanFetchTotalPath || null);
|
|
956
|
+
merged.fetchHasMorePath = pick('fetchHasMorePath', d.zidanFetchHasMorePath || null);
|
|
813
957
|
|
|
814
958
|
// carry over every explicitly-passed option (callbacks, custom classes, ...)
|
|
815
959
|
Object.keys(options).forEach(function (key) {
|
|
@@ -825,6 +969,11 @@
|
|
|
825
969
|
if (mode === 'combobox') merged.searchable = true;
|
|
826
970
|
if (mode === 'tags' && merged.searchable === false) merged.searchable = true;
|
|
827
971
|
if (mode === 'tags') merged.multiple = true;
|
|
972
|
+
|
|
973
|
+
// declarative AJAX: one URL is enough to opt into remote loading
|
|
974
|
+
if (merged.fetchUrl && typeof merged.fetchOptions !== 'function') {
|
|
975
|
+
merged.fetchOptions = createRemoteFetcher(merged);
|
|
976
|
+
}
|
|
828
977
|
return merged;
|
|
829
978
|
};
|
|
830
979
|
|
|
@@ -985,6 +1134,9 @@
|
|
|
985
1134
|
input.setAttribute('aria-controls', this.id + '-listbox');
|
|
986
1135
|
input.setAttribute('aria-autocomplete', (opts.searchable || this.mode !== 'select') ? 'list' : 'none');
|
|
987
1136
|
input.setAttribute('aria-haspopup', 'listbox');
|
|
1137
|
+
/* a plain select is not type-to-filter: keep its text field read-only so
|
|
1138
|
+
typing cannot filter or hide the options */
|
|
1139
|
+
if (this.mode === 'select' && !opts.searchable) input.readOnly = true;
|
|
988
1140
|
if (opts.ariaLabel || opts.label) input.setAttribute('aria-label', opts.ariaLabel || opts.label);
|
|
989
1141
|
if (opts.disabled) input.disabled = true;
|
|
990
1142
|
this._applyCustomClass(input, 'input');
|
|
@@ -994,6 +1146,16 @@
|
|
|
994
1146
|
labelEl = el('label', 'zs-label', { for: input.id });
|
|
995
1147
|
labelEl.textContent = opts.label;
|
|
996
1148
|
if (this.layout !== 'floating-label') rootEl.classList.add('zs-root--has-static-label');
|
|
1149
|
+
|
|
1150
|
+
// Hide the author's <label>: this label replaces it, and showing both
|
|
1151
|
+
// would print the same text twice above the control.
|
|
1152
|
+
var authorLabel = this.el.labels && this.el.labels[0] ? this.el.labels[0] : null;
|
|
1153
|
+
if (authorLabel && authorLabel.closest && authorLabel.closest('.zs-root')) authorLabel = null;
|
|
1154
|
+
this._authorLabel = authorLabel || null;
|
|
1155
|
+
if (authorLabel) {
|
|
1156
|
+
authorLabel.hidden = true;
|
|
1157
|
+
authorLabel.setAttribute('data-zs-hidden-label', 'true');
|
|
1158
|
+
}
|
|
997
1159
|
}
|
|
998
1160
|
|
|
999
1161
|
var clearBtn = el('button', 'zs-clear', {
|
|
@@ -1022,9 +1184,7 @@
|
|
|
1022
1184
|
var dropdown = el('div', 'zs-dropdown');
|
|
1023
1185
|
dropdown.id = this.id + '-listbox';
|
|
1024
1186
|
dropdown.setAttribute('role', 'listbox');
|
|
1025
|
-
|
|
1026
|
-
dropdown.setAttribute('aria-multiselectable', String(!!(opts.multiple || this.mode === 'tags')));
|
|
1027
|
-
}
|
|
1187
|
+
dropdown.setAttribute('aria-multiselectable', String(!!(opts.multiple || this.mode === 'tags')));
|
|
1028
1188
|
this._applyCustomClass(dropdown, 'dropdown');
|
|
1029
1189
|
|
|
1030
1190
|
var live = el('div', 'zs-live', { 'aria-live': 'polite', 'aria-atomic': 'true' });
|
|
@@ -1102,6 +1262,22 @@
|
|
|
1102
1262
|
};
|
|
1103
1263
|
this.form.addEventListener('reset', this.onFormReset);
|
|
1104
1264
|
}
|
|
1265
|
+
|
|
1266
|
+
/* `required` is a JS-only option as well as a native attribute. A native
|
|
1267
|
+
select can carry it directly; a mount-mode div needs a submit guard. */
|
|
1268
|
+
if (opts.required && this.native && this.native.tagName === 'SELECT' && !this.native.required) {
|
|
1269
|
+
this.native.required = true;
|
|
1270
|
+
this._nativeRequiredAdded = true;
|
|
1271
|
+
} else if (opts.required && !this.native && this.form) {
|
|
1272
|
+
this.onFormSubmit = function (event) {
|
|
1273
|
+
if (self.value_.length) return;
|
|
1274
|
+
event.preventDefault();
|
|
1275
|
+
self.setValidation('invalid');
|
|
1276
|
+
if (self.input && self.input.focus) self.input.focus();
|
|
1277
|
+
self.announce('Please select an option.');
|
|
1278
|
+
};
|
|
1279
|
+
this.form.addEventListener('submit', this.onFormSubmit);
|
|
1280
|
+
}
|
|
1105
1281
|
return this.syncEl;
|
|
1106
1282
|
};
|
|
1107
1283
|
|
|
@@ -1202,7 +1378,9 @@
|
|
|
1202
1378
|
|
|
1203
1379
|
if (!this.opts.multiple && this.mode !== 'tags') next = next.slice(0, 1);
|
|
1204
1380
|
this.value_ = next;
|
|
1205
|
-
|
|
1381
|
+
/* a preset/manual invalid state is only cleared by a real value change, not
|
|
1382
|
+
by the initial value applied during construction */
|
|
1383
|
+
if (next.length && this.opts.validation === 'invalid' && !cfg.silent) this.opts.validation = null;
|
|
1206
1384
|
this._render();
|
|
1207
1385
|
this._syncNative();
|
|
1208
1386
|
if (!cfg.silent) {
|
|
@@ -1915,6 +2093,22 @@
|
|
|
1915
2093
|
return false;
|
|
1916
2094
|
}
|
|
1917
2095
|
|
|
2096
|
+
/* allowFreeText: false limits tags to the supplied option/suggestion list */
|
|
2097
|
+
if (this.mode === 'tags' && !opts.allowFreeText) {
|
|
2098
|
+
var pool = this.suggestions && this.suggestions.length ? this.suggestions : this.items;
|
|
2099
|
+
var needle = opts.caseSensitive ? raw : raw.toLowerCase();
|
|
2100
|
+
var listed = false;
|
|
2101
|
+
for (var s = 0; s < pool.length; s += 1) {
|
|
2102
|
+
var itemValue = opts.caseSensitive ? String(pool[s].value) : String(pool[s].value).toLowerCase();
|
|
2103
|
+
var itemLabel = opts.caseSensitive ? String(pool[s].label) : String(pool[s].label).toLowerCase();
|
|
2104
|
+
if (itemValue === needle || itemLabel === needle) { listed = true; break; }
|
|
2105
|
+
}
|
|
2106
|
+
if (!listed) {
|
|
2107
|
+
if (!cfg.silent) this._tagError('"' + raw + '" is not in the list.');
|
|
2108
|
+
return false;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
1918
2112
|
var formatted = raw;
|
|
1919
2113
|
if (typeof opts.formatTag === 'function') {
|
|
1920
2114
|
var formattedResult = opts.formatTag(raw, { instance: this, tags: this.getTags() });
|
|
@@ -1991,6 +2185,14 @@
|
|
|
1991
2185
|
var key = event.key;
|
|
1992
2186
|
var items = this._visibleItems();
|
|
1993
2187
|
|
|
2188
|
+
/* Space opens a closed combobox/listbox (WAI-ARIA), unless the user is
|
|
2189
|
+
already typing a search or tag query in an open control. */
|
|
2190
|
+
if ((key === ' ' || key === 'Spacebar') && !this.opened) {
|
|
2191
|
+
event.preventDefault();
|
|
2192
|
+
this.open();
|
|
2193
|
+
return;
|
|
2194
|
+
}
|
|
2195
|
+
|
|
1994
2196
|
if (key === 'ArrowDown' || key === 'ArrowUp') {
|
|
1995
2197
|
event.preventDefault();
|
|
1996
2198
|
if (!this.opened) {
|
|
@@ -2126,6 +2328,8 @@
|
|
|
2126
2328
|
|
|
2127
2329
|
this.onInput = function () {
|
|
2128
2330
|
var value = self.input.value;
|
|
2331
|
+
/* plain selects are not searchable: typing must not filter the list */
|
|
2332
|
+
if (self.mode === 'select' && !self.opts.searchable) return;
|
|
2129
2333
|
self.query = value;
|
|
2130
2334
|
if (self.opened) {
|
|
2131
2335
|
if (typeof self.opts.fetchOptions === 'function' && self.query.length >= (self.opts.minChars || 0)) {
|
|
@@ -2519,6 +2723,11 @@
|
|
|
2519
2723
|
this.clearCache();
|
|
2520
2724
|
if (this.resizeObserver) this.resizeObserver.disconnect();
|
|
2521
2725
|
if (this.form && this.onFormReset) this.form.removeEventListener('reset', this.onFormReset);
|
|
2726
|
+
if (this.form && this.onFormSubmit) this.form.removeEventListener('submit', this.onFormSubmit);
|
|
2727
|
+
if (this._nativeRequiredAdded && this.native) {
|
|
2728
|
+
this.native.required = false;
|
|
2729
|
+
this._nativeRequiredAdded = false;
|
|
2730
|
+
}
|
|
2522
2731
|
|
|
2523
2732
|
doc.removeEventListener('pointerdown', this.onDocumentPointerDown, true);
|
|
2524
2733
|
global.removeEventListener('resize', this.onWindowResize);
|
|
@@ -2528,6 +2737,12 @@
|
|
|
2528
2737
|
|
|
2529
2738
|
if (this.root && this.root.parentNode) this.root.parentNode.removeChild(this.root);
|
|
2530
2739
|
|
|
2740
|
+
if (this._authorLabel) {
|
|
2741
|
+
this._authorLabel.hidden = false;
|
|
2742
|
+
this._authorLabel.removeAttribute('data-zs-hidden-label');
|
|
2743
|
+
this._authorLabel = null;
|
|
2744
|
+
}
|
|
2745
|
+
|
|
2531
2746
|
if (this.native) {
|
|
2532
2747
|
this.native.hidden = false;
|
|
2533
2748
|
this.native.classList.remove('zs-native');
|
|
@@ -2569,6 +2784,8 @@
|
|
|
2569
2784
|
var RADIO_VARIANTS = ['stacked', 'inline', 'card', 'button', 'tile'];
|
|
2570
2785
|
var FILE_VARIANTS = ['dropzone', 'button', 'avatar', 'gallery', 'compact'];
|
|
2571
2786
|
var RANGE_VARIANTS = ['default', 'gradient', 'stepped', 'minimal'];
|
|
2787
|
+
var RANGE_BUBBLE_MODES = ['always', 'active', 'never'];
|
|
2788
|
+
var RANGE_BUBBLE_POSITIONS = ['top', 'bottom'];
|
|
2572
2789
|
|
|
2573
2790
|
function textWithout(rootNode, skip) {
|
|
2574
2791
|
var out = '';
|
|
@@ -2607,6 +2824,7 @@
|
|
|
2607
2824
|
this.destroyed = false;
|
|
2608
2825
|
this._listeners = [];
|
|
2609
2826
|
this._cleanups = [];
|
|
2827
|
+
this._describedByBefore = [];
|
|
2610
2828
|
this.formEl = target.form || (target.closest ? target.closest('form') : null);
|
|
2611
2829
|
var scope = resolveScope(target, this.opts);
|
|
2612
2830
|
this.theme = scope.theme;
|
|
@@ -2738,11 +2956,12 @@
|
|
|
2738
2956
|
this._setCustomValidity(message && custom ? message : '');
|
|
2739
2957
|
if (message) {
|
|
2740
2958
|
if (show) this.setError(message);
|
|
2741
|
-
else this.setValidation('invalid');
|
|
2959
|
+
else this.setValidation('invalid', true);
|
|
2742
2960
|
return this;
|
|
2743
2961
|
}
|
|
2744
2962
|
if (this.errorMessage) this.setError(null);
|
|
2745
|
-
|
|
2963
|
+
/* keep an initial or manually set invalid state until the user interacts */
|
|
2964
|
+
if (this.validation === 'invalid' && !this._presetValidation) this.setValidation(null, true);
|
|
2746
2965
|
return this;
|
|
2747
2966
|
};
|
|
2748
2967
|
|
|
@@ -2807,6 +3026,22 @@
|
|
|
2807
3026
|
return Promise.resolve(!result.error);
|
|
2808
3027
|
};
|
|
2809
3028
|
|
|
3029
|
+
ZidanFieldBase.prototype._trackDescribedBy = function (input) {
|
|
3030
|
+
if (!input || !input.getAttribute) return;
|
|
3031
|
+
for (var i = 0; i < this._describedByBefore.length; i += 1) {
|
|
3032
|
+
if (this._describedByBefore[i][0] === input) return;
|
|
3033
|
+
}
|
|
3034
|
+
this._describedByBefore.push([input, input.getAttribute('aria-describedby')]);
|
|
3035
|
+
};
|
|
3036
|
+
|
|
3037
|
+
ZidanFieldBase.prototype._addDescribedBy = function (input, id) {
|
|
3038
|
+
if (!input || !input.getAttribute || !id) return;
|
|
3039
|
+
this._trackDescribedBy(input);
|
|
3040
|
+
var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
3041
|
+
if (current.indexOf(id) === -1) current.push(id);
|
|
3042
|
+
input.setAttribute('aria-describedby', current.join(' '));
|
|
3043
|
+
};
|
|
3044
|
+
|
|
2810
3045
|
ZidanFieldBase.prototype._syncDescribedBy = function () {
|
|
2811
3046
|
if (!this.el || !this.el.getAttribute) return;
|
|
2812
3047
|
var errorId = this.id + '-error';
|
|
@@ -2815,6 +3050,7 @@
|
|
|
2815
3050
|
var targets = this.validationTargets();
|
|
2816
3051
|
targets.forEach(function (input) {
|
|
2817
3052
|
if (!input || !input.getAttribute) return;
|
|
3053
|
+
this._trackDescribedBy(input);
|
|
2818
3054
|
var current = (input.getAttribute('aria-describedby') || '').split(/\s+/).filter(Boolean);
|
|
2819
3055
|
var next = current.filter(function (id) { return id !== errorId && id !== hintId; });
|
|
2820
3056
|
if (hintId) next.push(hintId);
|
|
@@ -2882,10 +3118,17 @@
|
|
|
2882
3118
|
});
|
|
2883
3119
|
self.on(input, 'blur', function () {
|
|
2884
3120
|
self.touched = true;
|
|
3121
|
+
self._presetValidation = false;
|
|
3122
|
+
self._mirrorValidity();
|
|
3123
|
+
});
|
|
3124
|
+
self.on(input, 'input', function () {
|
|
3125
|
+
self._presetValidation = false;
|
|
3126
|
+
self._mirrorValidity();
|
|
3127
|
+
});
|
|
3128
|
+
self.on(input, 'change', function () {
|
|
3129
|
+
self._presetValidation = false;
|
|
2885
3130
|
self._mirrorValidity();
|
|
2886
3131
|
});
|
|
2887
|
-
self.on(input, 'input', function () { self._mirrorValidity(); });
|
|
2888
|
-
self.on(input, 'change', function () { self._mirrorValidity(); });
|
|
2889
3132
|
});
|
|
2890
3133
|
this.on(this.formEl, 'reset', function () {
|
|
2891
3134
|
global.setTimeout(function () {
|
|
@@ -2934,8 +3177,10 @@
|
|
|
2934
3177
|
return true;
|
|
2935
3178
|
};
|
|
2936
3179
|
|
|
2937
|
-
ZidanFieldBase.prototype.setValidation = function (state) {
|
|
3180
|
+
ZidanFieldBase.prototype.setValidation = function (state, internal) {
|
|
2938
3181
|
this.validation = VALIDATION_STATES.indexOf(state) === -1 ? null : state;
|
|
3182
|
+
/* public calls pin the state; internal mirrors may clear it again */
|
|
3183
|
+
if (!internal) this._presetValidation = this.validation === 'invalid';
|
|
2939
3184
|
var invalid = this.validation === 'invalid' || !!this.errorMessage;
|
|
2940
3185
|
if (this.root) {
|
|
2941
3186
|
this.root.classList.toggle('zs-field--invalid', invalid);
|
|
@@ -3026,7 +3271,16 @@
|
|
|
3026
3271
|
this._cleanups.forEach(function (fn) { fn(); });
|
|
3027
3272
|
this._cleanups.length = 0;
|
|
3028
3273
|
this.emit('destroy', {});
|
|
3029
|
-
|
|
3274
|
+
/* radio groups use the author's <fieldset> as their root: removing it would
|
|
3275
|
+
delete the original radios too, so only remove roots the field created. */
|
|
3276
|
+
if (this.root && this.root !== this.el && this.root.parentNode) this.root.parentNode.removeChild(this.root);
|
|
3277
|
+
this._describedByBefore.forEach(function (entry) {
|
|
3278
|
+
var input = entry[0];
|
|
3279
|
+
if (!input || !input.getAttribute) return;
|
|
3280
|
+
if (entry[1] === null || entry[1] === undefined) input.removeAttribute('aria-describedby');
|
|
3281
|
+
else input.setAttribute('aria-describedby', entry[1]);
|
|
3282
|
+
});
|
|
3283
|
+
this._describedByBefore = [];
|
|
3030
3284
|
if (this.el.__zidanField === this) delete this.el.__zidanField;
|
|
3031
3285
|
ZidanForm._unregister(this);
|
|
3032
3286
|
return this;
|
|
@@ -3130,8 +3384,7 @@
|
|
|
3130
3384
|
if (hintText) {
|
|
3131
3385
|
var hint = el('p', 'zs-field__hint', { id: this.id + '-hint' }, hintText);
|
|
3132
3386
|
root.appendChild(hint);
|
|
3133
|
-
|
|
3134
|
-
this._cleanups.push(function () { input.removeAttribute('aria-describedby'); });
|
|
3387
|
+
this._addDescribedBy(input, this.id + '-hint');
|
|
3135
3388
|
}
|
|
3136
3389
|
|
|
3137
3390
|
this.check = check;
|
|
@@ -3220,6 +3473,12 @@
|
|
|
3220
3473
|
|
|
3221
3474
|
function ZidanRadioGroup(target, options) {
|
|
3222
3475
|
if (!(this instanceof ZidanRadioGroup)) return new ZidanRadioGroup(target, options);
|
|
3476
|
+
/* radios are enhanced as a group, never one input at a time */
|
|
3477
|
+
if (isElement(target) && /^INPUT$/i.test(target.tagName)) {
|
|
3478
|
+
var group = target.closest ? target.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
3479
|
+
if (!group) throw new Error('ZidanRadioGroup: expected a <fieldset> containing the radio inputs.');
|
|
3480
|
+
target = group;
|
|
3481
|
+
}
|
|
3223
3482
|
ZidanFieldBase.call(this, target, options, 'radio-group');
|
|
3224
3483
|
var variant = pickList(this.opts.variant || target.getAttribute('data-zidan-variant'), RADIO_VARIANTS, 'stacked');
|
|
3225
3484
|
this.variant = variant;
|
|
@@ -3229,7 +3488,14 @@
|
|
|
3229
3488
|
target.setAttribute('data-zs-kind', 'radio-group');
|
|
3230
3489
|
target.setAttribute('data-zs-variant', variant);
|
|
3231
3490
|
this._applyScope(target);
|
|
3232
|
-
|
|
3491
|
+
var hadRole = target.hasAttribute('role');
|
|
3492
|
+
if (!hadRole) target.setAttribute('role', 'radiogroup');
|
|
3493
|
+
this._teardown = function () {
|
|
3494
|
+
target.classList.remove('zs-radio-group');
|
|
3495
|
+
['data-zs-kind', 'data-zs-variant', 'data-zs-theme', 'data-zs-framework', 'data-zs-layout']
|
|
3496
|
+
.forEach(function (name) { target.removeAttribute(name); });
|
|
3497
|
+
if (!hadRole) target.removeAttribute('role');
|
|
3498
|
+
};
|
|
3233
3499
|
this._labels = [];
|
|
3234
3500
|
this._enhance();
|
|
3235
3501
|
this._bindValidity();
|
|
@@ -3559,6 +3825,22 @@
|
|
|
3559
3825
|
|
|
3560
3826
|
self.on(clearBtn, 'click', function () { self.clear(); });
|
|
3561
3827
|
|
|
3828
|
+
/* Delegated once: the list is rebuilt on every upload progress tick, so
|
|
3829
|
+
per-item listeners would grow without bound. */
|
|
3830
|
+
self.on(list, 'click', function (event) {
|
|
3831
|
+
var button = event.target && event.target.closest ? event.target.closest('button') : null;
|
|
3832
|
+
if (!button || !list.contains(button)) return;
|
|
3833
|
+
var item = button.closest('.zs-file-item');
|
|
3834
|
+
var index = item ? parseInt(item.getAttribute('data-zs-file-index'), 10) : -1;
|
|
3835
|
+
var file = index >= 0 ? self.getFiles()[index] : null;
|
|
3836
|
+
if (!file) return;
|
|
3837
|
+
event.preventDefault();
|
|
3838
|
+
event.stopPropagation();
|
|
3839
|
+
if (button.classList.contains('zs-file-cancel')) self.cancelUpload(file);
|
|
3840
|
+
else if (button.classList.contains('zs-file-retry')) self.retryUpload(file);
|
|
3841
|
+
else if (button.classList.contains('zs-file-remove')) self.removeFile(file);
|
|
3842
|
+
});
|
|
3843
|
+
|
|
3562
3844
|
this._bindValidity();
|
|
3563
3845
|
this.on(this.formEl, 'reset', function () {
|
|
3564
3846
|
global.setTimeout(function () {
|
|
@@ -3855,6 +4137,7 @@
|
|
|
3855
4137
|
var state = self._stateFor(file, false) || { status: 'idle', progress: 0, error: '', result: null };
|
|
3856
4138
|
var item = el('li', 'zs-file-item');
|
|
3857
4139
|
item.setAttribute('data-zs-upload-state', state.status);
|
|
4140
|
+
item.setAttribute('data-zs-file-index', String(index));
|
|
3858
4141
|
|
|
3859
4142
|
var thumb = el('span', 'zs-file-thumb');
|
|
3860
4143
|
if (/^image\//.test(file.type)) {
|
|
@@ -3904,30 +4187,15 @@
|
|
|
3904
4187
|
if (state.status === 'uploading') {
|
|
3905
4188
|
var cancel = el('button', 'zs-file-cancel', { type: 'button', 'aria-label': 'Cancel upload of ' + file.name });
|
|
3906
4189
|
cancel.textContent = opts.cancelLabel || 'Cancel';
|
|
3907
|
-
self.on(cancel, 'click', function (event) {
|
|
3908
|
-
event.preventDefault();
|
|
3909
|
-
event.stopPropagation();
|
|
3910
|
-
self.cancelUpload(file);
|
|
3911
|
-
});
|
|
3912
4190
|
actions.appendChild(cancel);
|
|
3913
4191
|
} else if (state.status === 'error' || state.status === 'canceled') {
|
|
3914
4192
|
var retry = el('button', 'zs-file-retry', { type: 'button', 'aria-label': 'Retry upload of ' + file.name });
|
|
3915
4193
|
retry.textContent = opts.retryLabel || 'Retry';
|
|
3916
|
-
self.on(retry, 'click', function (event) {
|
|
3917
|
-
event.preventDefault();
|
|
3918
|
-
event.stopPropagation();
|
|
3919
|
-
self.retryUpload(file);
|
|
3920
|
-
});
|
|
3921
4194
|
actions.appendChild(retry);
|
|
3922
4195
|
}
|
|
3923
4196
|
|
|
3924
4197
|
var remove = el('button', 'zs-file-remove', { type: 'button', 'aria-label': 'Remove ' + file.name });
|
|
3925
4198
|
remove.textContent = '\u00d7';
|
|
3926
|
-
self.on(remove, 'click', function (event) {
|
|
3927
|
-
event.preventDefault();
|
|
3928
|
-
event.stopPropagation();
|
|
3929
|
-
self.removeFile(file);
|
|
3930
|
-
});
|
|
3931
4199
|
actions.appendChild(remove);
|
|
3932
4200
|
|
|
3933
4201
|
item.appendChild(thumb);
|
|
@@ -4284,8 +4552,10 @@
|
|
|
4284
4552
|
iso = String(iso).toUpperCase();
|
|
4285
4553
|
var country = PHONE_COUNTRIES[iso];
|
|
4286
4554
|
if (!country) return;
|
|
4555
|
+
/* ISO + dial only: Windows renders flag emoji as the two ISO letters,
|
|
4556
|
+
which duplicated the code ("GB GB +44"). */
|
|
4287
4557
|
var optionNode = el('option', null, { value: iso },
|
|
4288
|
-
|
|
4558
|
+
iso + ' +' + country.dial);
|
|
4289
4559
|
countrySelect.appendChild(optionNode);
|
|
4290
4560
|
});
|
|
4291
4561
|
countrySelect.value = phoneCountry;
|
|
@@ -4370,12 +4640,23 @@
|
|
|
4370
4640
|
if (isRange) {
|
|
4371
4641
|
var rangeVariant = pickList(fieldOption(input, opts, 'rangeVariant', 'range-variant', 'default'), RANGE_VARIANTS, 'default');
|
|
4372
4642
|
var rangeBubbleOn = fieldBool(input, opts, 'rangeBubble', 'range-bubble', true);
|
|
4643
|
+
var rangeBubbleMode = pickList(fieldOption(input, opts, 'rangeBubbleMode', 'range-bubble-mode', 'always'), RANGE_BUBBLE_MODES, 'always');
|
|
4644
|
+
var rangeBubblePosition = pickList(fieldOption(input, opts, 'rangeBubblePosition', 'range-bubble-position', 'top'), RANGE_BUBBLE_POSITIONS, 'top');
|
|
4645
|
+
var rangeFillOn = fieldBool(input, opts, 'rangeFill', 'range-fill', true);
|
|
4373
4646
|
var rangeScaleOn = fieldBool(input, opts, 'rangeMinMax', 'range-minmax', true);
|
|
4647
|
+
var showBubble = rangeBubbleOn && rangeBubbleMode !== 'never';
|
|
4648
|
+
var bubbleVisible = showBubble && rangeVariant !== 'minimal';
|
|
4374
4649
|
rangeWrap = el('div', 'zs-range');
|
|
4375
4650
|
rangeWrap.setAttribute('data-zs-range', rangeVariant);
|
|
4376
|
-
|
|
4651
|
+
rangeWrap.classList.toggle('zs-range--fill-off', !rangeFillOn);
|
|
4652
|
+
rangeWrap.classList.toggle('zs-range--no-bubble', !bubbleVisible);
|
|
4653
|
+
if (showBubble) {
|
|
4377
4654
|
rangeBubble = el('output', 'zs-range-bubble', { for: this.id, 'aria-hidden': 'true' });
|
|
4378
4655
|
rangeWrap.appendChild(rangeBubble);
|
|
4656
|
+
if (bubbleVisible) {
|
|
4657
|
+
rangeWrap.classList.toggle('zs-range--bubble-active', rangeBubbleMode === 'active');
|
|
4658
|
+
rangeWrap.classList.toggle('zs-range--bubble-bottom', rangeBubblePosition === 'bottom');
|
|
4659
|
+
}
|
|
4379
4660
|
}
|
|
4380
4661
|
rangeWrap.appendChild(input);
|
|
4381
4662
|
rangeTicksEl = el('div', 'zs-range-ticks', { 'aria-hidden': 'true' });
|
|
@@ -4393,7 +4674,11 @@
|
|
|
4393
4674
|
this.rangeTicksEl = rangeTicksEl;
|
|
4394
4675
|
this.rangeScale = rangeScale;
|
|
4395
4676
|
this.rangeFormat = opts.rangeFormat || input.getAttribute('data-zidan-range-format') || null;
|
|
4396
|
-
this.
|
|
4677
|
+
this.rangeBubbleMode = rangeBubbleMode;
|
|
4678
|
+
this.rangeBubblePosition = rangeBubblePosition;
|
|
4679
|
+
this.rangeMinLabel = String(fieldOption(input, opts, 'rangeMinLabel', 'range-min-label', ''));
|
|
4680
|
+
this.rangeMaxLabel = String(fieldOption(input, opts, 'rangeMaxLabel', 'range-max-label', ''));
|
|
4681
|
+
this.rangeTicksOption = parseRangeTicks(fieldOption(input, opts, 'rangeTicks', 'range-ticks', 0));
|
|
4397
4682
|
this.rangeTickLabels = fieldBool(input, opts, 'rangeTickLabels', 'range-tick-labels', false);
|
|
4398
4683
|
this.rangeLabelMap = opts.rangeLabels || null;
|
|
4399
4684
|
this.rangeSignature = '';
|
|
@@ -4613,7 +4898,8 @@
|
|
|
4613
4898
|
|
|
4614
4899
|
var outputSelector = opts.output || input.getAttribute('data-zidan-output');
|
|
4615
4900
|
if (isRange && outputSelector) {
|
|
4616
|
-
var out =
|
|
4901
|
+
var out = null;
|
|
4902
|
+
try { out = doc.querySelector(outputSelector); } catch (err) { out = null; }
|
|
4617
4903
|
if (out) {
|
|
4618
4904
|
this.rangeOutput = out;
|
|
4619
4905
|
}
|
|
@@ -4685,28 +4971,45 @@
|
|
|
4685
4971
|
return { min: min, max: max };
|
|
4686
4972
|
};
|
|
4687
4973
|
|
|
4974
|
+
ZidanTextField.prototype._rangeLabelFor = function (value) {
|
|
4975
|
+
if (this.rangeLabelMap && this.rangeLabelMap[value] !== undefined) {
|
|
4976
|
+
return String(this.rangeLabelMap[value]);
|
|
4977
|
+
}
|
|
4978
|
+
return this._formatRangeValue(value);
|
|
4979
|
+
};
|
|
4980
|
+
|
|
4688
4981
|
ZidanTextField.prototype._renderRangeTicks = function () {
|
|
4689
4982
|
if (!this.rangeTicksEl) return;
|
|
4690
4983
|
var bounds = this._rangeBounds();
|
|
4691
4984
|
var option = this.rangeTicksOption;
|
|
4985
|
+
var labelsOn = !!this.rangeTickLabels;
|
|
4986
|
+
this.rangeTicksEl.textContent = '';
|
|
4692
4987
|
var values = [];
|
|
4693
|
-
if (Array.isArray(option))
|
|
4694
|
-
|
|
4988
|
+
if (Array.isArray(option)) {
|
|
4989
|
+
values = option.map(Number).filter(function (n) { return isFinite(n); });
|
|
4990
|
+
} else {
|
|
4695
4991
|
var count = parseInt(option, 10);
|
|
4696
|
-
if (
|
|
4697
|
-
|
|
4992
|
+
if (count > 1) {
|
|
4993
|
+
for (var i = 0; i < count; i += 1) values.push(bounds.min + ((bounds.max - bounds.min) * i) / (count - 1));
|
|
4994
|
+
}
|
|
4698
4995
|
}
|
|
4699
|
-
|
|
4996
|
+
/* Labeled ticks at both ends replace the min/max scale, so the start and end
|
|
4997
|
+
numbers are printed once instead of twice. */
|
|
4998
|
+
var coversEnds = labelsOn && !!this.rangeScale && values.length > 0 &&
|
|
4999
|
+
values.indexOf(bounds.min) !== -1 && values.indexOf(bounds.max) !== -1;
|
|
5000
|
+
if (this.rangeScale) this.rangeScale.classList.toggle('zs-range-scale--hidden', coversEnds);
|
|
5001
|
+
/* with no scale row, tick labels need their own room so they cannot overlap
|
|
5002
|
+
whatever follows the range */
|
|
5003
|
+
this.range.classList.toggle('zs-range--labels-no-scale', labelsOn && !this.rangeScale && values.length > 0);
|
|
4700
5004
|
values.forEach(function (value) {
|
|
4701
5005
|
var pct = bounds.max > bounds.min ? (value - bounds.min) / (bounds.max - bounds.min) : 0;
|
|
4702
5006
|
var tick = el('span', 'zs-range-tick');
|
|
4703
5007
|
tick.style.setProperty('--zs-range-tick-pct', (clamp(pct, 0, 1) * 100).toFixed(2) + '%');
|
|
4704
|
-
if (
|
|
4705
|
-
|
|
4706
|
-
? this.rangeLabelMap[value]
|
|
4707
|
-
: this._formatRangeValue(value);
|
|
4708
|
-
tick.textContent = label;
|
|
5008
|
+
if (labelsOn) {
|
|
5009
|
+
tick.textContent = this._rangeLabelFor(value);
|
|
4709
5010
|
tick.classList.add('zs-range-tick--labeled');
|
|
5011
|
+
if (pct <= 0) tick.classList.add('zs-range-tick--start');
|
|
5012
|
+
else if (pct >= 1) tick.classList.add('zs-range-tick--end');
|
|
4710
5013
|
}
|
|
4711
5014
|
this.rangeTicksEl.appendChild(tick);
|
|
4712
5015
|
}, this);
|
|
@@ -4721,12 +5024,24 @@
|
|
|
4721
5024
|
pct = clamp(pct, 0, 1);
|
|
4722
5025
|
this.range.style.setProperty('--zs-range-pct', pct.toFixed(4));
|
|
4723
5026
|
this.range.style.setProperty('--zs-range-fill', (pct * 100).toFixed(2) + '%');
|
|
4724
|
-
if (this.rangeBubble)
|
|
4725
|
-
|
|
4726
|
-
|
|
4727
|
-
this.
|
|
5027
|
+
if (this.rangeBubble) {
|
|
5028
|
+
this.rangeBubble.textContent = this._formatRangeValue(numeric);
|
|
5029
|
+
/* at the ends, align the bubble inside the track instead of half outside it */
|
|
5030
|
+
this.rangeBubble.classList.toggle('zs-range-bubble--start', pct <= 0);
|
|
5031
|
+
this.rangeBubble.classList.toggle('zs-range-bubble--end', pct >= 1);
|
|
4728
5032
|
}
|
|
4729
|
-
|
|
5033
|
+
if (this.rangeScale) {
|
|
5034
|
+
this.rangeScale.firstChild.textContent = this.rangeMinLabel || this._formatRangeValue(bounds.min);
|
|
5035
|
+
this.rangeScale.lastChild.textContent = this.rangeMaxLabel || this._formatRangeValue(bounds.max);
|
|
5036
|
+
}
|
|
5037
|
+
/* the formatted value is what the user sees and what assistive tech should read */
|
|
5038
|
+
if (this.rangeFormat) this.el.setAttribute('aria-valuetext', this._formatRangeValue(numeric));
|
|
5039
|
+
else this.el.removeAttribute('aria-valuetext');
|
|
5040
|
+
var signature = [
|
|
5041
|
+
bounds.min, bounds.max, this.el.step, JSON.stringify(this.rangeTicksOption), this.rangeTickLabels,
|
|
5042
|
+
JSON.stringify(this.rangeLabelMap || null), this.rangeMinLabel, this.rangeMaxLabel,
|
|
5043
|
+
String(this.rangeFormat || '')
|
|
5044
|
+
].join('|');
|
|
4730
5045
|
if (signature !== this.rangeSignature) {
|
|
4731
5046
|
this.rangeSignature = signature;
|
|
4732
5047
|
this._renderRangeTicks();
|
|
@@ -4736,8 +5051,9 @@
|
|
|
4736
5051
|
ZidanTextField.prototype._syncRangeOutput = function (value) {
|
|
4737
5052
|
if (this.range) this._syncRange(value);
|
|
4738
5053
|
if (this.rangeOutput) {
|
|
4739
|
-
this.
|
|
4740
|
-
this.rangeOutput.
|
|
5054
|
+
var display = this.range ? this._formatRangeValue(value) : value;
|
|
5055
|
+
this.rangeOutput.textContent = display;
|
|
5056
|
+
this.rangeOutput.value = display;
|
|
4741
5057
|
}
|
|
4742
5058
|
};
|
|
4743
5059
|
|
|
@@ -4932,8 +5248,9 @@
|
|
|
4932
5248
|
}
|
|
4933
5249
|
if (this.range) this._syncRange(value);
|
|
4934
5250
|
if (this.rangeOutput) {
|
|
4935
|
-
this.
|
|
4936
|
-
this.rangeOutput.
|
|
5251
|
+
var display = this.range ? this._formatRangeValue(value) : value;
|
|
5252
|
+
this.rangeOutput.textContent = display;
|
|
5253
|
+
this.rangeOutput.value = display;
|
|
4937
5254
|
}
|
|
4938
5255
|
if (this.stepper) {
|
|
4939
5256
|
var min = parseFloat(input.min);
|
|
@@ -4957,6 +5274,7 @@
|
|
|
4957
5274
|
};
|
|
4958
5275
|
|
|
4959
5276
|
ZidanTextField.prototype._teardown = function () {
|
|
5277
|
+
if (this.range) this.el.removeAttribute('aria-valuetext');
|
|
4960
5278
|
if (this._restoreInput) this._restoreInput();
|
|
4961
5279
|
};
|
|
4962
5280
|
|
|
@@ -5022,7 +5340,11 @@
|
|
|
5022
5340
|
// (output, counter, clearable, …) work without a data attribute
|
|
5023
5341
|
var kind = fieldKindFor(node) || inferredTextKind(node);
|
|
5024
5342
|
if (!kind) return;
|
|
5025
|
-
if (kind === 'radio'
|
|
5343
|
+
if (kind === 'radio' || kind === 'radio-group') {
|
|
5344
|
+
if (/^INPUT$/i.test(node.tagName)) {
|
|
5345
|
+
node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
5346
|
+
if (!node) return;
|
|
5347
|
+
}
|
|
5026
5348
|
kind = 'radio-group';
|
|
5027
5349
|
}
|
|
5028
5350
|
var instance = createField(node, kind, options || {});
|
|
@@ -5037,7 +5359,13 @@
|
|
|
5037
5359
|
if (!isElement(node) || node.__zidanField) return;
|
|
5038
5360
|
var kind = fieldKindFor(node);
|
|
5039
5361
|
if (!kind) return;
|
|
5040
|
-
if (kind === 'radio'
|
|
5362
|
+
if (kind === 'radio' || kind === 'radio-group') {
|
|
5363
|
+
if (/^INPUT$/i.test(node.tagName)) {
|
|
5364
|
+
node = node.closest ? node.closest('fieldset, [data-zidan-radio-group]') : null;
|
|
5365
|
+
if (!node) return;
|
|
5366
|
+
}
|
|
5367
|
+
kind = 'radio-group';
|
|
5368
|
+
}
|
|
5041
5369
|
var instance = createField(node, kind, options || {});
|
|
5042
5370
|
if (instance) instances.push(instance);
|
|
5043
5371
|
});
|