@mgdis/mg-components 5.17.0 → 5.18.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/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/mg-action-more_34.cjs.entry.js +464 -157
- package/dist/cjs/mg-action-more_34.cjs.entry.js.map +1 -1
- package/dist/cjs/mg-components.cjs.js +1 -1
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js +31 -11
- package/dist/collection/components/atoms/mg-tooltip/mg-tooltip.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.e2e.js +6 -0
- package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.e2e.js.map +1 -1
- package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.spec.js +8 -0
- package/dist/collection/components/atoms/mg-tooltip/test/mg-tooltip.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js +92 -16
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/test/mg-input-checkbox.spec.js +58 -1
- package/dist/collection/components/molecules/inputs/mg-input-checkbox/test/mg-input-checkbox.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js +79 -8
- package/dist/collection/components/molecules/inputs/mg-input-date/mg-input-date.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-date/test/mg-input-date.spec.js +55 -0
- package/dist/collection/components/molecules/inputs/mg-input-date/test/mg-input-date.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js +109 -38
- package/dist/collection/components/molecules/inputs/mg-input-numeric/mg-input-numeric.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-numeric/test/mg-input-numeric.spec.js +55 -0
- package/dist/collection/components/molecules/inputs/mg-input-numeric/test/mg-input-numeric.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js +83 -10
- package/dist/collection/components/molecules/inputs/mg-input-password/mg-input-password.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-password/test/mg-input-password.spec.js +55 -0
- package/dist/collection/components/molecules/inputs/mg-input-password/test/mg-input-password.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js +82 -9
- package/dist/collection/components/molecules/inputs/mg-input-radio/mg-input-radio.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-radio/test/mg-input-radio.spec.js +60 -0
- package/dist/collection/components/molecules/inputs/mg-input-radio/test/mg-input-radio.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js +82 -9
- package/dist/collection/components/molecules/inputs/mg-input-select/mg-input-select.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-select/test/mg-input-select.spec.js +55 -0
- package/dist/collection/components/molecules/inputs/mg-input-select/test/mg-input-select.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js +94 -21
- package/dist/collection/components/molecules/inputs/mg-input-text/mg-input-text.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-text/test/mg-input-text.spec.js +68 -5
- package/dist/collection/components/molecules/inputs/mg-input-text/test/mg-input-text.spec.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js +100 -26
- package/dist/collection/components/molecules/inputs/mg-input-textarea/mg-input-textarea.js.map +1 -1
- package/dist/collection/components/molecules/inputs/mg-input-textarea/test/mg-input-textarea.spec.js +67 -4
- package/dist/collection/components/molecules/inputs/mg-input-textarea/test/mg-input-textarea.spec.js.map +1 -1
- package/dist/collection/components/molecules/mg-form/mg-form.js +2 -2
- package/dist/collection/components/molecules/mg-form/mg-form.js.map +1 -1
- package/dist/collection/components/molecules/mg-panel/mg-panel.js +8 -6
- package/dist/collection/components/molecules/mg-panel/mg-panel.js.map +1 -1
- package/dist/collection/components/molecules/mg-panel/test/mg-panel.e2e.playwright.js +1 -1
- package/dist/collection/components/molecules/mg-panel/test/mg-panel.e2e.playwright.js.map +1 -1
- package/dist/collection/components/molecules/mg-panel/test/mg-panel.spec.js +3 -13
- package/dist/collection/components/molecules/mg-panel/test/mg-panel.spec.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/mg-popover.js +34 -14
- package/dist/collection/components/molecules/mg-popover/mg-popover.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/test/mg-popover.e2e.js +13 -2
- package/dist/collection/components/molecules/mg-popover/test/mg-popover.e2e.js.map +1 -1
- package/dist/collection/components/molecules/mg-popover/test/mg-popover.spec.js +12 -0
- package/dist/collection/components/molecules/mg-popover/test/mg-popover.spec.js.map +1 -1
- package/dist/collection/utils/components.utils.js +6 -0
- package/dist/collection/utils/components.utils.js.map +1 -1
- package/dist/collection/utils/components.utils.spec.js +9 -1
- package/dist/collection/utils/components.utils.spec.js.map +1 -1
- package/dist/components/components.utils.js +7 -1
- package/dist/components/components.utils.js.map +1 -1
- package/dist/components/mg-form.js +1 -1
- package/dist/components/mg-form.js.map +1 -1
- package/dist/components/mg-input-checkbox.js +52 -13
- package/dist/components/mg-input-checkbox.js.map +1 -1
- package/dist/components/mg-input-date.js +41 -8
- package/dist/components/mg-input-date.js.map +1 -1
- package/dist/components/mg-input-numeric.js +71 -38
- package/dist/components/mg-input-numeric.js.map +1 -1
- package/dist/components/mg-input-password.js +45 -10
- package/dist/components/mg-input-password.js.map +1 -1
- package/dist/components/mg-input-radio.js +44 -9
- package/dist/components/mg-input-radio.js.map +1 -1
- package/dist/components/mg-input-select2.js +44 -9
- package/dist/components/mg-input-select2.js.map +1 -1
- package/dist/components/mg-input-text2.js +56 -23
- package/dist/components/mg-input-text2.js.map +1 -1
- package/dist/components/mg-input-textarea.js +60 -26
- package/dist/components/mg-input-textarea.js.map +1 -1
- package/dist/components/mg-panel.js +8 -7
- package/dist/components/mg-panel.js.map +1 -1
- package/dist/components/mg-popover2.js +33 -14
- package/dist/components/mg-popover2.js.map +1 -1
- package/dist/components/mg-tooltip2.js +30 -11
- package/dist/components/mg-tooltip2.js.map +1 -1
- package/dist/esm/loader.js +1 -1
- package/dist/esm/mg-action-more_34.entry.js +464 -157
- package/dist/esm/mg-action-more_34.entry.js.map +1 -1
- package/dist/esm/mg-components.js +1 -1
- package/dist/mg-components/mg-components.esm.js +1 -1
- package/dist/mg-components/mg-components.esm.js.map +1 -1
- package/dist/mg-components/p-ff3ca349.entry.js +2 -0
- package/dist/mg-components/p-ff3ca349.entry.js.map +1 -0
- package/dist/types/components/atoms/mg-tooltip/mg-tooltip.d.ts +2 -1
- package/dist/types/components/molecules/inputs/mg-input-checkbox/mg-input-checkbox.d.ts +22 -1
- package/dist/types/components/molecules/inputs/mg-input-date/mg-input-date.d.ts +17 -2
- package/dist/types/components/molecules/inputs/mg-input-numeric/mg-input-numeric.d.ts +35 -20
- package/dist/types/components/molecules/inputs/mg-input-password/mg-input-password.d.ts +16 -1
- package/dist/types/components/molecules/inputs/mg-input-radio/mg-input-radio.d.ts +16 -1
- package/dist/types/components/molecules/inputs/mg-input-select/mg-input-select.d.ts +16 -1
- package/dist/types/components/molecules/inputs/mg-input-text/mg-input-text.d.ts +17 -5
- package/dist/types/components/molecules/inputs/mg-input-textarea/mg-input-textarea.d.ts +17 -5
- package/dist/types/components/molecules/mg-form/mg-form.d.ts +1 -1
- package/dist/types/components/molecules/mg-panel/mg-panel.d.ts +1 -1
- package/dist/types/components/molecules/mg-popover/mg-popover.d.ts +1 -0
- package/dist/types/components.d.ts +59 -11
- package/dist/types/utils/components.utils.d.ts +6 -0
- package/package.json +1 -1
- package/dist/mg-components/p-caafc9cf.entry.js +0 -2
- package/dist/mg-components/p-caafc9cf.entry.js.map +0 -1
|
@@ -148,6 +148,12 @@ const getChildWindows = (localWindow, windows = []) => {
|
|
|
148
148
|
}
|
|
149
149
|
return windows;
|
|
150
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* Validate string
|
|
153
|
+
* @param value - value to check
|
|
154
|
+
* @returns if string is valid
|
|
155
|
+
*/
|
|
156
|
+
const isValidString = (value) => typeof value === 'string' && value.trim() !== '';
|
|
151
157
|
|
|
152
158
|
const mgActionMoreCss = ".sr-only{border:0 !important;clip:rect(1px, 1px, 1px, 1px) !important;-webkit-clip-path:inset(50%) !important;clip-path:inset(50%) !important;height:1px !important;margin:-1px !important;overflow:hidden !important;padding:0 !important;position:absolute !important;width:1px !important;white-space:nowrap !important}*:focus:not(:focus-visible){outline:none}@media (prefers-reduced-motion){.mg-a11y-animation{animation:none !important;transition:none !important}}:host{--mg-popover-padding-vertical:1rem;--mg-popover-padding-horizontal:0;--mg-popover-max-width:unset}.mg-action-more__chevron{transition:200ms}.mg-action-more__chevron--rotate.mg-action-more__chevron{transform:rotate(180deg)}";
|
|
153
159
|
|
|
@@ -791,7 +797,7 @@ const MgForm = class {
|
|
|
791
797
|
this.setRequiredMessage();
|
|
792
798
|
}
|
|
793
799
|
/**
|
|
794
|
-
*
|
|
800
|
+
* Display input error if it exists.
|
|
795
801
|
*/
|
|
796
802
|
async displayError() {
|
|
797
803
|
if (!this.readonly) {
|
|
@@ -1586,6 +1592,7 @@ const MgInputCheckbox = class {
|
|
|
1586
1592
|
this.inputValid = createEvent(this, "input-valid", 7);
|
|
1587
1593
|
// hasDisplayedError (triggered by blur event)
|
|
1588
1594
|
this.hasDisplayedError = false;
|
|
1595
|
+
this.mode = 'custom';
|
|
1589
1596
|
// style
|
|
1590
1597
|
this.baseClassName = 'mg-input--checkbox';
|
|
1591
1598
|
// "multi" setup
|
|
@@ -1685,10 +1692,7 @@ const MgInputCheckbox = class {
|
|
|
1685
1692
|
* Check if input is valid
|
|
1686
1693
|
*/
|
|
1687
1694
|
this.checkValidity = () => {
|
|
1688
|
-
this.
|
|
1689
|
-
this.invalid = !this.valid;
|
|
1690
|
-
// We need to send valid event even if it is the same value
|
|
1691
|
-
this.inputValid.emit(this.valid);
|
|
1695
|
+
this.setValidity(this.readonly || this.disabled || (this.getInvalidElement() === undefined && this.validateRequired()));
|
|
1692
1696
|
};
|
|
1693
1697
|
/**
|
|
1694
1698
|
* Render button text
|
|
@@ -1706,12 +1710,17 @@ const MgInputCheckbox = class {
|
|
|
1706
1710
|
/**
|
|
1707
1711
|
* Set input error message
|
|
1708
1712
|
* @param displayError - dispay error condition
|
|
1713
|
+
* @param errorMessage - errorMessage override
|
|
1709
1714
|
*/
|
|
1710
|
-
this.setErrorMessage = (displayError = true) => {
|
|
1715
|
+
this.setErrorMessage = (displayError = true, errorMessage) => {
|
|
1711
1716
|
// Set error message
|
|
1712
1717
|
this.errorMessage = undefined;
|
|
1713
|
-
if (displayError && !this.valid
|
|
1714
|
-
|
|
1718
|
+
if (displayError && !this.valid) {
|
|
1719
|
+
if (errorMessage !== undefined)
|
|
1720
|
+
this.errorMessage = errorMessage;
|
|
1721
|
+
else if (!this.validateRequired())
|
|
1722
|
+
this.errorMessage = this.messages.errors.required;
|
|
1723
|
+
}
|
|
1715
1724
|
};
|
|
1716
1725
|
/**
|
|
1717
1726
|
* Method to get mg-popover identifier
|
|
@@ -1724,7 +1733,7 @@ const MgInputCheckbox = class {
|
|
|
1724
1733
|
*/
|
|
1725
1734
|
this.getDisplayItems = () => (this.searchValue.length > 0 ? this.searchResults : this.checkboxItems);
|
|
1726
1735
|
this.value = undefined;
|
|
1727
|
-
this.type =
|
|
1736
|
+
this.type = undefined;
|
|
1728
1737
|
this.identifier = undefined;
|
|
1729
1738
|
this.name = this.identifier;
|
|
1730
1739
|
this.label = undefined;
|
|
@@ -1765,9 +1774,13 @@ const MgInputCheckbox = class {
|
|
|
1765
1774
|
}
|
|
1766
1775
|
}
|
|
1767
1776
|
validateType(newValue) {
|
|
1768
|
-
if (!checkboxTypes.includes(newValue)) {
|
|
1777
|
+
if (newValue !== undefined && !checkboxTypes.includes(newValue)) {
|
|
1769
1778
|
throw new Error('<mg-input-checkbox> prop "type" must be a CheckboxType.');
|
|
1770
1779
|
}
|
|
1780
|
+
else if (newValue === undefined) {
|
|
1781
|
+
this.mode = 'auto';
|
|
1782
|
+
this.type = checkboxTypes[0];
|
|
1783
|
+
}
|
|
1771
1784
|
else {
|
|
1772
1785
|
const className = `${this.baseClassName}-multi`;
|
|
1773
1786
|
if (newValue === 'multi') {
|
|
@@ -1799,9 +1812,9 @@ const MgInputCheckbox = class {
|
|
|
1799
1812
|
this.classCollection.delete(className);
|
|
1800
1813
|
}
|
|
1801
1814
|
validateCheckboxItems(newValue) {
|
|
1802
|
-
if (newValue.length > this.multiStart)
|
|
1815
|
+
if (this.mode === 'auto' && newValue.length > this.multiStart)
|
|
1803
1816
|
this.type = 'multi';
|
|
1804
|
-
if (newValue.length > this.searchStart) {
|
|
1817
|
+
if (this.mode === 'auto' || (this.type === 'multi' && newValue.length > this.searchStart)) {
|
|
1805
1818
|
this.displaySearchInput = this.type === 'multi';
|
|
1806
1819
|
// refresh search values
|
|
1807
1820
|
this.updateSearchResults();
|
|
@@ -1812,13 +1825,44 @@ const MgInputCheckbox = class {
|
|
|
1812
1825
|
this.updateSearchResults();
|
|
1813
1826
|
}
|
|
1814
1827
|
/**
|
|
1815
|
-
*
|
|
1828
|
+
* Display input error if it exists.
|
|
1816
1829
|
*/
|
|
1817
1830
|
async displayError() {
|
|
1818
1831
|
this.checkValidity();
|
|
1819
1832
|
this.setErrorMessage();
|
|
1820
1833
|
this.hasDisplayedError = this.invalid;
|
|
1821
1834
|
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Set an error and display a custom error message.
|
|
1837
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
1838
|
+
* It must be paired with an error message to display for the given context.
|
|
1839
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
1840
|
+
* @param valid - value indicating the validity
|
|
1841
|
+
* @param errorMessage - the error message to display
|
|
1842
|
+
*/
|
|
1843
|
+
async setError(valid, errorMessage) {
|
|
1844
|
+
if (typeof valid !== 'boolean') {
|
|
1845
|
+
throw new Error('<mg-input-checkbox> method "setError()" param "valid" must be a boolean');
|
|
1846
|
+
}
|
|
1847
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
1848
|
+
throw new Error('<mg-input-checkbox> method "setError()" param "errorMessage" must be a string');
|
|
1849
|
+
}
|
|
1850
|
+
else {
|
|
1851
|
+
this.setValidity(valid);
|
|
1852
|
+
this.setErrorMessage(undefined, valid ? undefined : errorMessage);
|
|
1853
|
+
this.hasDisplayedError = this.invalid;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
/**
|
|
1857
|
+
* Method to set validity values
|
|
1858
|
+
* @param newValue - valid new value
|
|
1859
|
+
*/
|
|
1860
|
+
setValidity(newValue) {
|
|
1861
|
+
this.valid = newValue;
|
|
1862
|
+
this.invalid = !this.valid;
|
|
1863
|
+
// We need to send valid event even if it is the same value
|
|
1864
|
+
this.inputValid.emit(this.valid);
|
|
1865
|
+
}
|
|
1822
1866
|
/**
|
|
1823
1867
|
* Update ckecboxes item
|
|
1824
1868
|
* @param key - property to update
|
|
@@ -2075,10 +2119,7 @@ const MgInputDate = class {
|
|
|
2075
2119
|
*/
|
|
2076
2120
|
this.checkValidity = () => {
|
|
2077
2121
|
var _a;
|
|
2078
|
-
this.
|
|
2079
|
-
this.invalid = !this.valid;
|
|
2080
|
-
// We need to send valid event even if it is the same value
|
|
2081
|
-
this.inputValid.emit(this.valid);
|
|
2122
|
+
this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
|
|
2082
2123
|
};
|
|
2083
2124
|
/**
|
|
2084
2125
|
* get input error code
|
|
@@ -2107,15 +2148,19 @@ const MgInputDate = class {
|
|
|
2107
2148
|
};
|
|
2108
2149
|
/**
|
|
2109
2150
|
* Check input errors
|
|
2151
|
+
* @param errorMessage - errorMessage override
|
|
2110
2152
|
*/
|
|
2111
|
-
this.setErrorMessage = () => {
|
|
2153
|
+
this.setErrorMessage = (errorMessage) => {
|
|
2112
2154
|
var _a;
|
|
2113
2155
|
// Set error message
|
|
2114
2156
|
this.errorMessage = undefined;
|
|
2115
2157
|
if (!this.valid) {
|
|
2116
2158
|
const inputError = this.getInputError();
|
|
2159
|
+
if (errorMessage !== undefined) {
|
|
2160
|
+
this.errorMessage = errorMessage;
|
|
2161
|
+
}
|
|
2117
2162
|
// required
|
|
2118
|
-
if (inputError === InputError$1.REQUIRED) {
|
|
2163
|
+
else if (inputError === InputError$1.REQUIRED) {
|
|
2119
2164
|
this.errorMessage = this.messages.errors[inputError];
|
|
2120
2165
|
}
|
|
2121
2166
|
// min, max & minMax
|
|
@@ -2174,13 +2219,44 @@ const MgInputDate = class {
|
|
|
2174
2219
|
}
|
|
2175
2220
|
}
|
|
2176
2221
|
/**
|
|
2177
|
-
*
|
|
2222
|
+
* Display input error if it exists.
|
|
2178
2223
|
*/
|
|
2179
2224
|
async displayError() {
|
|
2180
2225
|
this.checkValidity();
|
|
2181
2226
|
this.setErrorMessage();
|
|
2182
2227
|
this.hasDisplayedError = this.invalid;
|
|
2183
2228
|
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Set an error and display a custom error message.
|
|
2231
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
2232
|
+
* It must be paired with an error message to display for the given context.
|
|
2233
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
2234
|
+
* @param valid - value indicating the validity
|
|
2235
|
+
* @param errorMessage - the error message to display
|
|
2236
|
+
*/
|
|
2237
|
+
async setError(valid, errorMessage) {
|
|
2238
|
+
if (typeof valid !== 'boolean') {
|
|
2239
|
+
throw new Error('<mg-input-date> method "setError()" param "valid" must be a boolean');
|
|
2240
|
+
}
|
|
2241
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
2242
|
+
throw new Error('<mg-input-date> method "setError()" param "errorMessage" must be a string');
|
|
2243
|
+
}
|
|
2244
|
+
else {
|
|
2245
|
+
this.setValidity(valid);
|
|
2246
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
2247
|
+
this.hasDisplayedError = this.invalid;
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
/**
|
|
2251
|
+
* Method to set validity values
|
|
2252
|
+
* @param newValue - valid new value
|
|
2253
|
+
*/
|
|
2254
|
+
setValidity(newValue) {
|
|
2255
|
+
this.valid = newValue;
|
|
2256
|
+
this.invalid = !this.valid;
|
|
2257
|
+
// We need to send valid event even if it is the same value
|
|
2258
|
+
this.inputValid.emit(this.valid);
|
|
2259
|
+
}
|
|
2184
2260
|
/*************
|
|
2185
2261
|
* Lifecycle *
|
|
2186
2262
|
*************/
|
|
@@ -2278,20 +2354,21 @@ const MgInputNumeric = class {
|
|
|
2278
2354
|
* Check if input is valid
|
|
2279
2355
|
*/
|
|
2280
2356
|
this.checkValidity = () => {
|
|
2281
|
-
this.
|
|
2282
|
-
this.invalid = !this.valid;
|
|
2283
|
-
// We need to send valid event even if it is the same value
|
|
2284
|
-
this.inputValid.emit(this.valid);
|
|
2357
|
+
this.setValidity(this.readonly || this.disabled || this.getInputError() === null);
|
|
2285
2358
|
};
|
|
2286
2359
|
/**
|
|
2287
2360
|
* Set input error message
|
|
2361
|
+
* @param errorMessage - errorMessage override
|
|
2288
2362
|
*/
|
|
2289
|
-
this.setErrorMessage = () => {
|
|
2363
|
+
this.setErrorMessage = (errorMessage) => {
|
|
2290
2364
|
// Set error message
|
|
2291
2365
|
this.errorMessage = undefined;
|
|
2292
2366
|
if (!this.valid) {
|
|
2293
2367
|
const inputError = this.getInputError();
|
|
2294
|
-
if (
|
|
2368
|
+
if (errorMessage !== undefined) {
|
|
2369
|
+
this.errorMessage = errorMessage;
|
|
2370
|
+
}
|
|
2371
|
+
else if (inputError === InputError.REQUIRED) {
|
|
2295
2372
|
this.errorMessage = this.messages.errors[inputError];
|
|
2296
2373
|
}
|
|
2297
2374
|
else {
|
|
@@ -2385,36 +2462,6 @@ const MgInputNumeric = class {
|
|
|
2385
2462
|
this.updateValues(newValue);
|
|
2386
2463
|
}
|
|
2387
2464
|
}
|
|
2388
|
-
/**
|
|
2389
|
-
* Checks if the given value is valid according to the defined rules.
|
|
2390
|
-
* @param value - The input value to validate.
|
|
2391
|
-
* @param regex - The regular expression for validation.
|
|
2392
|
-
* @param integer - The integer part of the value.
|
|
2393
|
-
* @param decimal - The decimal part of the value.
|
|
2394
|
-
* @returns Returns true if the value is valid, otherwise false.
|
|
2395
|
-
*/
|
|
2396
|
-
isValidValue(value, regex, integer, decimal) {
|
|
2397
|
-
return ['', '-'].includes(value) || (value.match(regex) && integer.length <= this.integerLength && decimal.length <= (this.type === 'integer' ? 0 : this.decimalLength));
|
|
2398
|
-
}
|
|
2399
|
-
/**
|
|
2400
|
-
* Handles invalid input values and returns a corrected value.
|
|
2401
|
-
* @returns The corrected value.
|
|
2402
|
-
*/
|
|
2403
|
-
handleInvalidValue() {
|
|
2404
|
-
return this.storedValue !== undefined ? this.storedValue : null;
|
|
2405
|
-
}
|
|
2406
|
-
/**
|
|
2407
|
-
* Updates the component values based on the validated input value.
|
|
2408
|
-
* @param newValue - The validated input value.
|
|
2409
|
-
*/
|
|
2410
|
-
updateValues(newValue) {
|
|
2411
|
-
this.value = newValue;
|
|
2412
|
-
if (this.input !== undefined)
|
|
2413
|
-
this.input.value = this.value;
|
|
2414
|
-
this.numericValue = !['', null].includes(this.value) ? parseFloat(this.value.replace(',', '.')) : null;
|
|
2415
|
-
this.valueChange.emit(this.numericValue);
|
|
2416
|
-
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
2417
|
-
}
|
|
2418
2465
|
handleValidityChange(newValue, _oldValue, prop) {
|
|
2419
2466
|
if (this.input !== undefined) {
|
|
2420
2467
|
this.input[prop] = newValue;
|
|
@@ -2441,13 +2488,74 @@ const MgInputNumeric = class {
|
|
|
2441
2488
|
}
|
|
2442
2489
|
}
|
|
2443
2490
|
/**
|
|
2444
|
-
*
|
|
2491
|
+
* Display input error if it exists.
|
|
2445
2492
|
*/
|
|
2446
2493
|
async displayError() {
|
|
2447
2494
|
this.checkValidity();
|
|
2448
2495
|
this.setErrorMessage();
|
|
2449
2496
|
this.hasDisplayedError = this.invalid;
|
|
2450
2497
|
}
|
|
2498
|
+
/**
|
|
2499
|
+
* Set an error and display a custom error message.
|
|
2500
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
2501
|
+
* It must be paired with an error message to display for the given context.
|
|
2502
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
2503
|
+
* @param valid - value indicating the validity
|
|
2504
|
+
* @param errorMessage - the error message to display
|
|
2505
|
+
*/
|
|
2506
|
+
async setError(valid, errorMessage) {
|
|
2507
|
+
if (typeof valid !== 'boolean') {
|
|
2508
|
+
throw new Error('<mg-input-numeric> method "setError()" param "valid" must be a boolean');
|
|
2509
|
+
}
|
|
2510
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
2511
|
+
throw new Error('<mg-input-numeric> method "setError()" param "errorMessage" must be a string');
|
|
2512
|
+
}
|
|
2513
|
+
else {
|
|
2514
|
+
this.setValidity(valid);
|
|
2515
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
2516
|
+
this.hasDisplayedError = this.invalid;
|
|
2517
|
+
}
|
|
2518
|
+
}
|
|
2519
|
+
/**
|
|
2520
|
+
* Method to set validity values
|
|
2521
|
+
* @param newValue - valid new value
|
|
2522
|
+
*/
|
|
2523
|
+
setValidity(newValue) {
|
|
2524
|
+
this.valid = newValue;
|
|
2525
|
+
this.invalid = !this.valid;
|
|
2526
|
+
// We need to send valid event even if it is the same value
|
|
2527
|
+
this.inputValid.emit(this.valid);
|
|
2528
|
+
}
|
|
2529
|
+
/**
|
|
2530
|
+
* Checks if the given value is valid according to the defined rules.
|
|
2531
|
+
* @param value - The input value to validate.
|
|
2532
|
+
* @param regex - The regular expression for validation.
|
|
2533
|
+
* @param integer - The integer part of the value.
|
|
2534
|
+
* @param decimal - The decimal part of the value.
|
|
2535
|
+
* @returns Returns true if the value is valid, otherwise false.
|
|
2536
|
+
*/
|
|
2537
|
+
isValidValue(value, regex, integer, decimal) {
|
|
2538
|
+
return ['', '-'].includes(value) || (value.match(regex) && integer.length <= this.integerLength && decimal.length <= (this.type === 'integer' ? 0 : this.decimalLength));
|
|
2539
|
+
}
|
|
2540
|
+
/**
|
|
2541
|
+
* Handles invalid input values and returns a corrected value.
|
|
2542
|
+
* @returns The corrected value.
|
|
2543
|
+
*/
|
|
2544
|
+
handleInvalidValue() {
|
|
2545
|
+
return this.storedValue !== undefined ? this.storedValue : null;
|
|
2546
|
+
}
|
|
2547
|
+
/**
|
|
2548
|
+
* Updates the component values based on the validated input value.
|
|
2549
|
+
* @param newValue - The validated input value.
|
|
2550
|
+
*/
|
|
2551
|
+
updateValues(newValue) {
|
|
2552
|
+
this.value = newValue;
|
|
2553
|
+
if (this.input !== undefined)
|
|
2554
|
+
this.input.value = this.value;
|
|
2555
|
+
this.numericValue = !['', null].includes(this.value) ? parseFloat(this.value.replace(',', '.')) : null;
|
|
2556
|
+
this.valueChange.emit(this.numericValue);
|
|
2557
|
+
this.readonlyValue = this.numericValue !== null ? this.formatValue(this.numericValue) : '';
|
|
2558
|
+
}
|
|
2451
2559
|
/**
|
|
2452
2560
|
* Displayed value in input
|
|
2453
2561
|
* Change on focus/blur
|
|
@@ -2535,20 +2643,23 @@ const MgInputPassword = class {
|
|
|
2535
2643
|
*/
|
|
2536
2644
|
this.checkValidity = () => {
|
|
2537
2645
|
var _a;
|
|
2538
|
-
this.
|
|
2539
|
-
this.invalid = !this.valid;
|
|
2540
|
-
// We need to send valid event even if it is the same value
|
|
2541
|
-
this.inputValid.emit(this.valid);
|
|
2646
|
+
this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
|
|
2542
2647
|
};
|
|
2543
2648
|
/**
|
|
2544
2649
|
* Set input error message
|
|
2650
|
+
* @param errorMessage - errorMessage override
|
|
2545
2651
|
*/
|
|
2546
|
-
this.setErrorMessage = () => {
|
|
2652
|
+
this.setErrorMessage = (errorMessage) => {
|
|
2547
2653
|
// Set error message
|
|
2548
2654
|
this.errorMessage = undefined;
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2655
|
+
if (!this.valid) {
|
|
2656
|
+
if (errorMessage !== undefined) {
|
|
2657
|
+
this.errorMessage = errorMessage;
|
|
2658
|
+
}
|
|
2659
|
+
// required
|
|
2660
|
+
else if (this.input.validity.valueMissing) {
|
|
2661
|
+
this.errorMessage = this.messages.errors.required;
|
|
2662
|
+
}
|
|
2552
2663
|
}
|
|
2553
2664
|
};
|
|
2554
2665
|
this.value = undefined;
|
|
@@ -2583,13 +2694,44 @@ const MgInputPassword = class {
|
|
|
2583
2694
|
}
|
|
2584
2695
|
}
|
|
2585
2696
|
/**
|
|
2586
|
-
*
|
|
2697
|
+
* Display input error if it exists.
|
|
2587
2698
|
*/
|
|
2588
2699
|
async displayError() {
|
|
2589
2700
|
this.checkValidity();
|
|
2590
2701
|
this.setErrorMessage();
|
|
2591
2702
|
this.hasDisplayedError = this.invalid;
|
|
2592
2703
|
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Set an error and display a custom error message.
|
|
2706
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
2707
|
+
* It must be paired with an error message to display for the given context.
|
|
2708
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
2709
|
+
* @param valid - value indicating the validity
|
|
2710
|
+
* @param errorMessage - the error message to display
|
|
2711
|
+
*/
|
|
2712
|
+
async setError(valid, errorMessage) {
|
|
2713
|
+
if (typeof valid !== 'boolean') {
|
|
2714
|
+
throw new Error('<mg-input-password> method "setError()" param "valid" must be a boolean');
|
|
2715
|
+
}
|
|
2716
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
2717
|
+
throw new Error('<mg-input-password> method "setError()" param "errorMessage" must be a string');
|
|
2718
|
+
}
|
|
2719
|
+
else {
|
|
2720
|
+
this.setValidity(valid);
|
|
2721
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
2722
|
+
this.hasDisplayedError = this.invalid;
|
|
2723
|
+
}
|
|
2724
|
+
}
|
|
2725
|
+
/**
|
|
2726
|
+
* Method to set validity values
|
|
2727
|
+
* @param newValue - valid new value
|
|
2728
|
+
*/
|
|
2729
|
+
setValidity(newValue) {
|
|
2730
|
+
this.valid = newValue;
|
|
2731
|
+
this.invalid = !this.valid;
|
|
2732
|
+
// We need to send valid event even if it is the same value
|
|
2733
|
+
this.inputValid.emit(this.valid);
|
|
2734
|
+
}
|
|
2593
2735
|
/*************
|
|
2594
2736
|
* Lifecycle *
|
|
2595
2737
|
*************/
|
|
@@ -2666,20 +2808,23 @@ const MgInputRadio = class {
|
|
|
2666
2808
|
* Check if input is valid
|
|
2667
2809
|
*/
|
|
2668
2810
|
this.checkValidity = () => {
|
|
2669
|
-
this.
|
|
2670
|
-
this.invalid = !this.valid;
|
|
2671
|
-
// We need to send valid event even if it is the same value
|
|
2672
|
-
this.inputValid.emit(this.valid);
|
|
2811
|
+
this.setValidity(this.readonly || this.disabled || this.getInvalidElement() === undefined);
|
|
2673
2812
|
};
|
|
2674
2813
|
/**
|
|
2675
2814
|
* Set input error message
|
|
2815
|
+
* @param errorMessage - errorMessage override
|
|
2676
2816
|
*/
|
|
2677
|
-
this.setErrorMessage = () => {
|
|
2817
|
+
this.setErrorMessage = (errorMessage) => {
|
|
2678
2818
|
const invalidElement = this.getInvalidElement();
|
|
2679
2819
|
// Set error message
|
|
2680
2820
|
this.errorMessage = undefined;
|
|
2681
|
-
if (!this.valid
|
|
2682
|
-
|
|
2821
|
+
if (!this.valid) {
|
|
2822
|
+
if (errorMessage !== undefined) {
|
|
2823
|
+
this.errorMessage = errorMessage;
|
|
2824
|
+
}
|
|
2825
|
+
else if (invalidElement.validity.valueMissing) {
|
|
2826
|
+
this.errorMessage = this.messages.errors.required;
|
|
2827
|
+
}
|
|
2683
2828
|
}
|
|
2684
2829
|
};
|
|
2685
2830
|
/**
|
|
@@ -2737,13 +2882,44 @@ const MgInputRadio = class {
|
|
|
2737
2882
|
}
|
|
2738
2883
|
}
|
|
2739
2884
|
/**
|
|
2740
|
-
*
|
|
2885
|
+
* Display input error if it exists.
|
|
2741
2886
|
*/
|
|
2742
2887
|
async displayError() {
|
|
2743
2888
|
this.checkValidity();
|
|
2744
2889
|
this.setErrorMessage();
|
|
2745
2890
|
this.hasDisplayedError = this.invalid;
|
|
2746
2891
|
}
|
|
2892
|
+
/**
|
|
2893
|
+
* Set an error and display a custom error message.
|
|
2894
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
2895
|
+
* It must be paired with an error message to display for the given context.
|
|
2896
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
2897
|
+
* @param valid - value indicating the validity
|
|
2898
|
+
* @param errorMessage - the error message to display
|
|
2899
|
+
*/
|
|
2900
|
+
async setError(valid, errorMessage) {
|
|
2901
|
+
if (typeof valid !== 'boolean') {
|
|
2902
|
+
throw new Error('<mg-input-radio> method "setError()" param "valid" must be a boolean');
|
|
2903
|
+
}
|
|
2904
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
2905
|
+
throw new Error('<mg-input-radio> method "setError()" param "errorMessage" must be a string');
|
|
2906
|
+
}
|
|
2907
|
+
else {
|
|
2908
|
+
this.setValidity(valid);
|
|
2909
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
2910
|
+
this.hasDisplayedError = this.invalid;
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Method to set validity values
|
|
2915
|
+
* @param newValue - valid new value
|
|
2916
|
+
*/
|
|
2917
|
+
setValidity(newValue) {
|
|
2918
|
+
this.valid = newValue;
|
|
2919
|
+
this.invalid = !this.valid;
|
|
2920
|
+
// We need to send valid event even if it is the same value
|
|
2921
|
+
this.inputValid.emit(this.valid);
|
|
2922
|
+
}
|
|
2747
2923
|
/*************
|
|
2748
2924
|
* Lifecycle *
|
|
2749
2925
|
*************/
|
|
@@ -2892,19 +3068,22 @@ const MgInputSelect = class {
|
|
|
2892
3068
|
*/
|
|
2893
3069
|
this.checkValidity = () => {
|
|
2894
3070
|
var _a;
|
|
2895
|
-
this.
|
|
2896
|
-
this.invalid = !this.valid;
|
|
2897
|
-
// We need to send valid event even if it is the same value
|
|
2898
|
-
this.inputValid.emit(this.valid);
|
|
3071
|
+
this.setValidity(!this.isDisabledValue() && (this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true)));
|
|
2899
3072
|
};
|
|
2900
3073
|
/**
|
|
2901
3074
|
* Set input error message
|
|
3075
|
+
* @param errorMessage - errorMessage override
|
|
2902
3076
|
*/
|
|
2903
|
-
this.setErrorMessage = () => {
|
|
3077
|
+
this.setErrorMessage = (errorMessage) => {
|
|
2904
3078
|
// Set error message
|
|
2905
3079
|
this.errorMessage = undefined;
|
|
2906
|
-
if (!this.valid
|
|
2907
|
-
|
|
3080
|
+
if (!this.valid) {
|
|
3081
|
+
if (errorMessage !== undefined) {
|
|
3082
|
+
this.errorMessage = errorMessage;
|
|
3083
|
+
}
|
|
3084
|
+
else if (this.input.validity.valueMissing) {
|
|
3085
|
+
this.errorMessage = this.messages.errors.required;
|
|
3086
|
+
}
|
|
2908
3087
|
}
|
|
2909
3088
|
};
|
|
2910
3089
|
/**
|
|
@@ -2988,13 +3167,44 @@ const MgInputSelect = class {
|
|
|
2988
3167
|
}
|
|
2989
3168
|
}
|
|
2990
3169
|
/**
|
|
2991
|
-
*
|
|
3170
|
+
* Display input error if it exists.
|
|
2992
3171
|
*/
|
|
2993
3172
|
async displayError() {
|
|
2994
3173
|
this.checkValidity();
|
|
2995
3174
|
this.setErrorMessage();
|
|
2996
3175
|
this.hasDisplayedError = this.invalid;
|
|
2997
3176
|
}
|
|
3177
|
+
/**
|
|
3178
|
+
* Set an error and display a custom error message.
|
|
3179
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
3180
|
+
* It must be paired with an error message to display for the given context.
|
|
3181
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
3182
|
+
* @param valid - value indicating the validity
|
|
3183
|
+
* @param errorMessage - the error message to display
|
|
3184
|
+
*/
|
|
3185
|
+
async setError(valid, errorMessage) {
|
|
3186
|
+
if (typeof valid !== 'boolean') {
|
|
3187
|
+
throw new Error('<mg-input-select> method "setError()" param "valid" must be a boolean');
|
|
3188
|
+
}
|
|
3189
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
3190
|
+
throw new Error('<mg-input-select> method "setError()" param "errorMessage" must be a string');
|
|
3191
|
+
}
|
|
3192
|
+
else {
|
|
3193
|
+
this.setValidity(valid);
|
|
3194
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
3195
|
+
this.hasDisplayedError = this.invalid;
|
|
3196
|
+
}
|
|
3197
|
+
}
|
|
3198
|
+
/**
|
|
3199
|
+
* Method to set validity values
|
|
3200
|
+
* @param newValue - valid new value
|
|
3201
|
+
*/
|
|
3202
|
+
setValidity(newValue) {
|
|
3203
|
+
this.valid = newValue;
|
|
3204
|
+
this.invalid = !this.valid;
|
|
3205
|
+
// We need to send valid event even if it is the same value
|
|
3206
|
+
this.inputValid.emit(this.valid);
|
|
3207
|
+
}
|
|
2998
3208
|
/*************
|
|
2999
3209
|
* Lifecycle *
|
|
3000
3210
|
*************/
|
|
@@ -3089,19 +3299,21 @@ const MgInputText = class {
|
|
|
3089
3299
|
*/
|
|
3090
3300
|
this.checkValidity = () => {
|
|
3091
3301
|
var _a;
|
|
3092
|
-
this.
|
|
3093
|
-
this.invalid = !this.valid;
|
|
3094
|
-
// We need to send valid event even if it is the same value
|
|
3095
|
-
this.inputValid.emit(this.valid);
|
|
3302
|
+
this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined ? this.input.checkValidity() : true));
|
|
3096
3303
|
};
|
|
3097
3304
|
/**
|
|
3098
3305
|
* Set input error message
|
|
3306
|
+
* @param errorMessage - errorMessage override
|
|
3099
3307
|
*/
|
|
3100
|
-
this.setErrorMessage = () => {
|
|
3308
|
+
this.setErrorMessage = (errorMessage) => {
|
|
3101
3309
|
// Set error message
|
|
3102
3310
|
this.errorMessage = undefined;
|
|
3311
|
+
// Does have a custom error message
|
|
3312
|
+
if (!this.valid && errorMessage !== undefined) {
|
|
3313
|
+
this.errorMessage = errorMessage;
|
|
3314
|
+
}
|
|
3103
3315
|
// Does not match pattern
|
|
3104
|
-
if (!this.valid && this.input.validity.patternMismatch) {
|
|
3316
|
+
else if (!this.valid && this.input.validity.patternMismatch) {
|
|
3105
3317
|
this.errorMessage = this.patternErrorMessage;
|
|
3106
3318
|
}
|
|
3107
3319
|
// required
|
|
@@ -3109,17 +3321,6 @@ const MgInputText = class {
|
|
|
3109
3321
|
this.errorMessage = this.messages.errors.required;
|
|
3110
3322
|
}
|
|
3111
3323
|
};
|
|
3112
|
-
/**
|
|
3113
|
-
* Validate pattern configuration
|
|
3114
|
-
*/
|
|
3115
|
-
this.validatePattern = () => {
|
|
3116
|
-
if (this.pattern !== undefined &&
|
|
3117
|
-
typeof this.pattern === 'string' &&
|
|
3118
|
-
this.pattern !== '' &&
|
|
3119
|
-
(this.patternErrorMessage === undefined || typeof this.patternErrorMessage !== 'string' || this.patternErrorMessage === '')) {
|
|
3120
|
-
throw new Error('<mg-input-text> prop "pattern" must be paired with the prop "patternErrorMessage"');
|
|
3121
|
-
}
|
|
3122
|
-
};
|
|
3123
3324
|
/**
|
|
3124
3325
|
* Validate append slot
|
|
3125
3326
|
*/
|
|
@@ -3178,6 +3379,11 @@ const MgInputText = class {
|
|
|
3178
3379
|
}
|
|
3179
3380
|
}
|
|
3180
3381
|
}
|
|
3382
|
+
validatePattern(newValue) {
|
|
3383
|
+
if (newValue !== undefined && !(isValidString(this.pattern) && isValidString(this.patternErrorMessage))) {
|
|
3384
|
+
throw new Error('<mg-input-text> props "pattern" and "patternErrorMessage" must be non-empty string and paired.');
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3181
3387
|
/**
|
|
3182
3388
|
* Public method to play input focus
|
|
3183
3389
|
*/
|
|
@@ -3185,13 +3391,44 @@ const MgInputText = class {
|
|
|
3185
3391
|
this.input.focus();
|
|
3186
3392
|
}
|
|
3187
3393
|
/**
|
|
3188
|
-
*
|
|
3394
|
+
* Display input error if it exists.
|
|
3189
3395
|
*/
|
|
3190
3396
|
async displayError() {
|
|
3191
3397
|
this.checkValidity();
|
|
3192
3398
|
this.setErrorMessage();
|
|
3193
3399
|
this.hasDisplayedError = this.invalid;
|
|
3194
3400
|
}
|
|
3401
|
+
/**
|
|
3402
|
+
* Set an error and display a custom error message.
|
|
3403
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
3404
|
+
* It must be paired with an error message to display for the given context.
|
|
3405
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
3406
|
+
* @param valid - value indicating the validity
|
|
3407
|
+
* @param errorMessage - the error message to display
|
|
3408
|
+
*/
|
|
3409
|
+
async setError(valid, errorMessage) {
|
|
3410
|
+
if (typeof valid !== 'boolean') {
|
|
3411
|
+
throw new Error('<mg-input-text> method "setError()" param "valid" must be a boolean');
|
|
3412
|
+
}
|
|
3413
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
3414
|
+
throw new Error('<mg-input-text> method "setError()" param "errorMessage" must be a string');
|
|
3415
|
+
}
|
|
3416
|
+
else {
|
|
3417
|
+
this.setValidity(valid);
|
|
3418
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
3419
|
+
this.hasDisplayedError = this.invalid;
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
/**
|
|
3423
|
+
* Method to set validity values
|
|
3424
|
+
* @param newValue - valid new value
|
|
3425
|
+
*/
|
|
3426
|
+
setValidity(newValue) {
|
|
3427
|
+
this.valid = newValue;
|
|
3428
|
+
this.invalid = !this.valid;
|
|
3429
|
+
// We need to send valid event even if it is the same value
|
|
3430
|
+
this.inputValid.emit(this.valid);
|
|
3431
|
+
}
|
|
3195
3432
|
/*************
|
|
3196
3433
|
* Lifecycle *
|
|
3197
3434
|
*************/
|
|
@@ -3205,7 +3442,8 @@ const MgInputText = class {
|
|
|
3205
3442
|
this.characterLeftId = `${this.identifier}-character-left`;
|
|
3206
3443
|
// Validate
|
|
3207
3444
|
this.validateIcon(this.icon);
|
|
3208
|
-
this.validatePattern();
|
|
3445
|
+
this.validatePattern(this.pattern);
|
|
3446
|
+
this.validatePattern(this.patternErrorMessage);
|
|
3209
3447
|
this.validateAppendSlot();
|
|
3210
3448
|
// Check validity when component is ready
|
|
3211
3449
|
// return a promise to process action only in the FIRST render().
|
|
@@ -3234,7 +3472,9 @@ const MgInputText = class {
|
|
|
3234
3472
|
"icon": ["validateIcon"],
|
|
3235
3473
|
"required": ["handleValidityChange"],
|
|
3236
3474
|
"readonly": ["handleValidityChange"],
|
|
3237
|
-
"disabled": ["handleValidityChange"]
|
|
3475
|
+
"disabled": ["handleValidityChange"],
|
|
3476
|
+
"pattern": ["validatePattern"],
|
|
3477
|
+
"patternErrorMessage": ["validatePattern"]
|
|
3238
3478
|
}; }
|
|
3239
3479
|
};
|
|
3240
3480
|
MgInputText.style = mgInputTextCss;
|
|
@@ -3292,35 +3532,27 @@ const MgInputTextarea = class {
|
|
|
3292
3532
|
*/
|
|
3293
3533
|
this.checkValidity = () => {
|
|
3294
3534
|
var _a;
|
|
3295
|
-
this.
|
|
3296
|
-
this.invalid = !this.valid;
|
|
3297
|
-
// We need to send valid event even if it is the same value
|
|
3298
|
-
this.inputValid.emit(this.valid);
|
|
3535
|
+
this.setValidity(this.readonly || this.disabled || (((_a = this.input) === null || _a === void 0 ? void 0 : _a.checkValidity) !== undefined && this.input.checkValidity() && this.getPatternValidity()));
|
|
3299
3536
|
};
|
|
3300
3537
|
/**
|
|
3301
3538
|
* Set input error message
|
|
3539
|
+
* @param errorMessage - errorMessage override
|
|
3302
3540
|
*/
|
|
3303
|
-
this.setErrorMessage = () => {
|
|
3541
|
+
this.setErrorMessage = (errorMessage) => {
|
|
3304
3542
|
// Set error message
|
|
3305
3543
|
this.errorMessage = undefined;
|
|
3306
3544
|
// Does not match pattern
|
|
3307
|
-
if (!this.valid
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
this.validatePattern = () => {
|
|
3319
|
-
if (this.pattern !== undefined &&
|
|
3320
|
-
typeof this.pattern === 'string' &&
|
|
3321
|
-
this.pattern !== '' &&
|
|
3322
|
-
(this.patternErrorMessage === undefined || typeof this.patternErrorMessage !== 'string' || this.patternErrorMessage === '')) {
|
|
3323
|
-
throw new Error('<mg-input-textarea> prop "pattern" must be paired with the prop "patternErrorMessage"');
|
|
3545
|
+
if (!this.valid) {
|
|
3546
|
+
if (errorMessage !== undefined) {
|
|
3547
|
+
this.errorMessage = errorMessage;
|
|
3548
|
+
}
|
|
3549
|
+
else if (!this.getPatternValidity()) {
|
|
3550
|
+
this.errorMessage = this.patternErrorMessage;
|
|
3551
|
+
}
|
|
3552
|
+
// required
|
|
3553
|
+
else if (this.input.validity.valueMissing) {
|
|
3554
|
+
this.errorMessage = this.messages.errors.required;
|
|
3555
|
+
}
|
|
3324
3556
|
}
|
|
3325
3557
|
};
|
|
3326
3558
|
this.value = undefined;
|
|
@@ -3361,6 +3593,11 @@ const MgInputTextarea = class {
|
|
|
3361
3593
|
}
|
|
3362
3594
|
}
|
|
3363
3595
|
}
|
|
3596
|
+
validatePattern(newValue) {
|
|
3597
|
+
if (newValue !== undefined && !(isValidString(this.pattern) && isValidString(this.patternErrorMessage))) {
|
|
3598
|
+
throw new Error('<mg-input-textarea> props "pattern" and "patternErrorMessage" must be non-empty string and paired.');
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3364
3601
|
validateDisplayCharacterLeft(newValue) {
|
|
3365
3602
|
if (newValue) {
|
|
3366
3603
|
this.classCollection.add(this.classHasDisplayCharacterLeft);
|
|
@@ -3370,13 +3607,44 @@ const MgInputTextarea = class {
|
|
|
3370
3607
|
}
|
|
3371
3608
|
}
|
|
3372
3609
|
/**
|
|
3373
|
-
*
|
|
3610
|
+
* Display input error if it exists.
|
|
3374
3611
|
*/
|
|
3375
3612
|
async displayError() {
|
|
3376
3613
|
this.checkValidity();
|
|
3377
3614
|
this.setErrorMessage();
|
|
3378
3615
|
this.hasDisplayedError = this.invalid;
|
|
3379
3616
|
}
|
|
3617
|
+
/**
|
|
3618
|
+
* Set an error and display a custom error message.
|
|
3619
|
+
* This method can be used to set the component's error state from its context by passing a boolean value to the `valid` parameter.
|
|
3620
|
+
* It must be paired with an error message to display for the given context.
|
|
3621
|
+
* When used to set validity to `false`, you should use this method again to reset the validity to `true`.
|
|
3622
|
+
* @param valid - value indicating the validity
|
|
3623
|
+
* @param errorMessage - the error message to display
|
|
3624
|
+
*/
|
|
3625
|
+
async setError(valid, errorMessage) {
|
|
3626
|
+
if (typeof valid !== 'boolean') {
|
|
3627
|
+
throw new Error('<mg-input-textarea> method "setError()" param "valid" must be a boolean');
|
|
3628
|
+
}
|
|
3629
|
+
else if (typeof errorMessage !== 'string' || errorMessage.trim() === '') {
|
|
3630
|
+
throw new Error('<mg-input-textarea> method "setError()" param "errorMessage" must be a string');
|
|
3631
|
+
}
|
|
3632
|
+
else {
|
|
3633
|
+
this.setValidity(valid);
|
|
3634
|
+
this.setErrorMessage(valid ? undefined : errorMessage);
|
|
3635
|
+
this.hasDisplayedError = this.invalid;
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
/**
|
|
3639
|
+
* Method to set validity values
|
|
3640
|
+
* @param newValue - valid new value
|
|
3641
|
+
*/
|
|
3642
|
+
setValidity(newValue) {
|
|
3643
|
+
this.valid = newValue;
|
|
3644
|
+
this.invalid = !this.valid;
|
|
3645
|
+
// We need to send valid event even if it is the same value
|
|
3646
|
+
this.inputValid.emit(this.valid);
|
|
3647
|
+
}
|
|
3380
3648
|
/*************
|
|
3381
3649
|
* Lifecycle *
|
|
3382
3650
|
*************/
|
|
@@ -3390,7 +3658,8 @@ const MgInputTextarea = class {
|
|
|
3390
3658
|
this.characterLeftId = `${this.identifier}-character-left`;
|
|
3391
3659
|
// Validate
|
|
3392
3660
|
this.validateDisplayCharacterLeft(this.displayCharacterLeft);
|
|
3393
|
-
this.validatePattern();
|
|
3661
|
+
this.validatePattern(this.pattern);
|
|
3662
|
+
this.validatePattern(this.patternErrorMessage);
|
|
3394
3663
|
// Check validity when component is ready
|
|
3395
3664
|
// return a promise to process action only in the FIRST render().
|
|
3396
3665
|
// https://stenciljs.com/docs/component-lifecycle#componentwillload
|
|
@@ -3419,6 +3688,8 @@ const MgInputTextarea = class {
|
|
|
3419
3688
|
"required": ["handleValidityChange"],
|
|
3420
3689
|
"readonly": ["handleValidityChange"],
|
|
3421
3690
|
"disabled": ["handleValidityChange"],
|
|
3691
|
+
"pattern": ["validatePattern"],
|
|
3692
|
+
"patternErrorMessage": ["validatePattern"],
|
|
3422
3693
|
"displayCharacterLeft": ["validateDisplayCharacterLeft"]
|
|
3423
3694
|
}; }
|
|
3424
3695
|
};
|
|
@@ -4695,11 +4966,9 @@ const MgPanel = class {
|
|
|
4695
4966
|
throw new Error('<mg-panel> prop "panelTitle" is required.');
|
|
4696
4967
|
this.titleChange.emit(newValue);
|
|
4697
4968
|
}
|
|
4698
|
-
|
|
4969
|
+
validateTitlePattern(newValue) {
|
|
4699
4970
|
if (newValue !== undefined && !this.titleEditable)
|
|
4700
|
-
throw new Error(
|
|
4701
|
-
if (newValue !== undefined && (this.titlePatternErrorMessage === undefined || this.titlePatternErrorMessage.trim() === ''))
|
|
4702
|
-
throw new Error('<mg-panel> prop "titlePattern" must be paired with the prop "titlePatternErrorMessage".');
|
|
4971
|
+
throw new Error(`<mg-panel> prop "titleEditable" must be set to "true".`);
|
|
4703
4972
|
}
|
|
4704
4973
|
validateTitlePosition(newValue) {
|
|
4705
4974
|
if (!titlePositions.includes(newValue))
|
|
@@ -4724,7 +4993,8 @@ const MgPanel = class {
|
|
|
4724
4993
|
// Get locales
|
|
4725
4994
|
this.messages = initLocales(this.element).messages;
|
|
4726
4995
|
// Validate
|
|
4727
|
-
this.
|
|
4996
|
+
this.validateTitlePattern(this.titlePattern);
|
|
4997
|
+
this.validateTitlePattern(this.titlePatternErrorMessage);
|
|
4728
4998
|
this.validatePanelTitle(this.panelTitle);
|
|
4729
4999
|
this.validateExpandToggleDisplay(this.expandToggleDisplay);
|
|
4730
5000
|
this.validateTitlePosition(this.titlePosition);
|
|
@@ -4748,7 +5018,8 @@ const MgPanel = class {
|
|
|
4748
5018
|
get element() { return getElement(this); }
|
|
4749
5019
|
static get watchers() { return {
|
|
4750
5020
|
"panelTitle": ["validatePanelTitle"],
|
|
4751
|
-
"titlePattern": ["
|
|
5021
|
+
"titlePattern": ["validateTitlePattern"],
|
|
5022
|
+
"titlePatternErrorMessage": ["validateTitlePattern"],
|
|
4752
5023
|
"titlePosition": ["validateTitlePosition"],
|
|
4753
5024
|
"expanded": ["handleExpanded"],
|
|
4754
5025
|
"expandToggleDisplay": ["validateExpandToggleDisplay"]
|
|
@@ -6608,21 +6879,27 @@ const MgPopover = class {
|
|
|
6608
6879
|
* Render popover content element
|
|
6609
6880
|
*/
|
|
6610
6881
|
this.renderPopoverContent = () => {
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
|
|
6614
|
-
|
|
6615
|
-
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6882
|
+
const mgPopoverContent = this.element.querySelector('mg-popover-content');
|
|
6883
|
+
if (mgPopoverContent === null) {
|
|
6884
|
+
this.mgPopoverContent = document.createElement('mg-popover-content');
|
|
6885
|
+
this.mgPopoverContent.setAttribute('slot', 'content');
|
|
6886
|
+
this.mgPopoverContent.setAttribute('id', this.identifier);
|
|
6887
|
+
this.mgPopoverContent.addEventListener('hide-content', this.handleHideContent);
|
|
6888
|
+
const arrow = document.createElement('div');
|
|
6889
|
+
arrow.setAttribute('slot', 'arrow');
|
|
6890
|
+
arrow.dataset.popperArrow = '';
|
|
6891
|
+
this.mgPopoverContent.appendChild(arrow);
|
|
6892
|
+
// insert elements in DOM
|
|
6893
|
+
['[slot="title"]', '[slot="content"]:not(mg-popover-content)'].forEach(slotType => {
|
|
6894
|
+
Array.from(this.element.querySelectorAll(slotType)).forEach(slot => {
|
|
6895
|
+
this.mgPopoverContent.appendChild(slot);
|
|
6896
|
+
});
|
|
6623
6897
|
});
|
|
6624
|
-
|
|
6625
|
-
|
|
6898
|
+
this.element.appendChild(this.mgPopoverContent);
|
|
6899
|
+
}
|
|
6900
|
+
else {
|
|
6901
|
+
mgPopoverContent.setAttribute('id', this.identifier);
|
|
6902
|
+
}
|
|
6626
6903
|
};
|
|
6627
6904
|
this.identifier = createID('mg-popover');
|
|
6628
6905
|
this.placement = 'bottom';
|
|
@@ -6631,6 +6908,10 @@ const MgPopover = class {
|
|
|
6631
6908
|
this.display = false;
|
|
6632
6909
|
this.disabled = false;
|
|
6633
6910
|
}
|
|
6911
|
+
validateIdentifier() {
|
|
6912
|
+
// use renderPopoverContent to update popover-content id
|
|
6913
|
+
this.renderPopoverContent();
|
|
6914
|
+
}
|
|
6634
6915
|
validateArrowHide(newValue) {
|
|
6635
6916
|
if (newValue)
|
|
6636
6917
|
this.mgPopoverContent.dataset.arrowHide = '';
|
|
@@ -6667,6 +6948,7 @@ const MgPopover = class {
|
|
|
6667
6948
|
// render mg-popover-content slot
|
|
6668
6949
|
this.renderPopoverContent();
|
|
6669
6950
|
this.validateCloseButton(this.closeButton);
|
|
6951
|
+
this.validateIdentifier();
|
|
6670
6952
|
this.validateArrowHide(this.arrowHide);
|
|
6671
6953
|
}
|
|
6672
6954
|
/**
|
|
@@ -6691,6 +6973,12 @@ const MgPopover = class {
|
|
|
6691
6973
|
offset: [0, 0],
|
|
6692
6974
|
},
|
|
6693
6975
|
},
|
|
6976
|
+
{
|
|
6977
|
+
name: 'flip',
|
|
6978
|
+
options: {
|
|
6979
|
+
fallbackPlacements: ['auto'],
|
|
6980
|
+
},
|
|
6981
|
+
},
|
|
6694
6982
|
],
|
|
6695
6983
|
});
|
|
6696
6984
|
// add resize observer
|
|
@@ -6720,6 +7008,7 @@ const MgPopover = class {
|
|
|
6720
7008
|
}
|
|
6721
7009
|
get element() { return getElement(this); }
|
|
6722
7010
|
static get watchers() { return {
|
|
7011
|
+
"identifier": ["validateIdentifier"],
|
|
6723
7012
|
"arrowHide": ["validateArrowHide"],
|
|
6724
7013
|
"closeButton": ["validateCloseButton"],
|
|
6725
7014
|
"display": ["handleDisplay"]
|
|
@@ -7302,6 +7591,12 @@ const MgTooltip = class {
|
|
|
7302
7591
|
offset: [0, 8],
|
|
7303
7592
|
},
|
|
7304
7593
|
},
|
|
7594
|
+
{
|
|
7595
|
+
name: 'flip',
|
|
7596
|
+
options: {
|
|
7597
|
+
fallbackPlacements: ['auto'],
|
|
7598
|
+
},
|
|
7599
|
+
},
|
|
7305
7600
|
],
|
|
7306
7601
|
});
|
|
7307
7602
|
// Manage tooltipedElement focus/blur events
|
|
@@ -7339,6 +7634,10 @@ const MgTooltip = class {
|
|
|
7339
7634
|
this.display = false;
|
|
7340
7635
|
this.disabled = false;
|
|
7341
7636
|
}
|
|
7637
|
+
validateIdentifier() {
|
|
7638
|
+
// use renderTooltipContent to update tooltip-content id
|
|
7639
|
+
this.renderTooltipContent();
|
|
7640
|
+
}
|
|
7342
7641
|
validateMessage(newValue) {
|
|
7343
7642
|
if (typeof newValue !== 'string' || newValue.trim() === '') {
|
|
7344
7643
|
throw new Error('<mg-tooltip> prop "message" is required.');
|
|
@@ -7364,16 +7663,22 @@ const MgTooltip = class {
|
|
|
7364
7663
|
/**
|
|
7365
7664
|
* Render tooltip content element
|
|
7366
7665
|
*/
|
|
7367
|
-
|
|
7368
|
-
const mgTooltipContent =
|
|
7369
|
-
mgTooltipContent
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
7375
|
-
|
|
7376
|
-
|
|
7666
|
+
renderTooltipContent() {
|
|
7667
|
+
const mgTooltipContent = this.element.querySelector('mg-tooltip-content');
|
|
7668
|
+
if (mgTooltipContent === null) {
|
|
7669
|
+
const mgTooltipContent = document.createElement('mg-tooltip-content');
|
|
7670
|
+
mgTooltipContent.setAttribute('slot', 'content');
|
|
7671
|
+
mgTooltipContent.setAttribute('id', this.identifier);
|
|
7672
|
+
const arrow = document.createElement('div');
|
|
7673
|
+
arrow.setAttribute('slot', 'arrow');
|
|
7674
|
+
arrow.dataset.popperArrow = '';
|
|
7675
|
+
mgTooltipContent.appendChild(arrow);
|
|
7676
|
+
// append tooltip element to component
|
|
7677
|
+
this.element.appendChild(mgTooltipContent);
|
|
7678
|
+
}
|
|
7679
|
+
else {
|
|
7680
|
+
mgTooltipContent.setAttribute('id', this.identifier);
|
|
7681
|
+
}
|
|
7377
7682
|
}
|
|
7378
7683
|
/*************
|
|
7379
7684
|
* Lifecycle *
|
|
@@ -7385,11 +7690,12 @@ const MgTooltip = class {
|
|
|
7385
7690
|
// Get windows to attach events
|
|
7386
7691
|
this.windows = getWindows(window);
|
|
7387
7692
|
// Get tooltip element
|
|
7388
|
-
this.
|
|
7693
|
+
this.renderTooltipContent();
|
|
7389
7694
|
this.mgTooltipContent = this.element.querySelector(`#${this.identifier}`);
|
|
7390
7695
|
//validate properties
|
|
7391
7696
|
this.validateDisabled(this.disabled);
|
|
7392
7697
|
this.validateMessage(this.message);
|
|
7698
|
+
this.validateIdentifier();
|
|
7393
7699
|
}
|
|
7394
7700
|
/**
|
|
7395
7701
|
* Get slotted element
|
|
@@ -7437,6 +7743,7 @@ const MgTooltip = class {
|
|
|
7437
7743
|
}
|
|
7438
7744
|
get element() { return getElement(this); }
|
|
7439
7745
|
static get watchers() { return {
|
|
7746
|
+
"identifier": ["validateIdentifier"],
|
|
7440
7747
|
"message": ["validateMessage"],
|
|
7441
7748
|
"display": ["handleDisplay"],
|
|
7442
7749
|
"disabled": ["validateDisabled"]
|