MCPcopy
hub / github.com/autoNumeric/autoNumeric / _setSettings

Method _setSettings

src/AutoNumeric.js:8489–8574  ·  view source on GitHub ↗

* Analyse the settings/options passed by the user, validate and clean them, then set them into `this.settings`. * Note: This sets the settings to `null` if somehow the settings object is undefined or empty * If only `decimalPlaces` is defined in the option, overwrite the other decima

(options, update = false)

Source from the content-addressed store, hash-verified

8487 * @throws
8488 */
8489 _setSettings(options, update = false) {
8490 // If the user used old options, we convert them to new ones
8491 if (update || !AutoNumericHelper.isNull(options)) {
8492 this.constructor._convertOldOptionsToNewOnes(options);
8493 }
8494
8495 if (update) {
8496 // The settings are updated
8497 // Update the original data, if it has changed
8498 const decimalPlacesRawValueInOptions = 'decimalPlacesRawValue' in options;
8499 if (decimalPlacesRawValueInOptions) {
8500 this.settings.originalDecimalPlacesRawValue = options.decimalPlacesRawValue;
8501 }
8502
8503 const decimalPlacesInOptions = 'decimalPlaces' in options;
8504 if (decimalPlacesInOptions) {
8505 this.settings.originalDecimalPlaces = options.decimalPlaces;
8506 }
8507
8508 // Then update all the `decimalPlaces*` options
8509 this.constructor._calculateDecimalPlacesOnUpdate(options, this.settings);
8510
8511 // Finally generate the updated settings object to use
8512 this._mergeSettings(options); //TODO Check that the `styleRules` option is correctly cloned (due to depth cloning limitation)
8513 } else {
8514 // The settings are generated for the first time
8515 this.settings = {};
8516 // If we couldn't grab any settings, create them from the default ones and combine them with the options passed as a parameter as well as with the HTML5 `data-*` info (via `this.domElement.dataset`), if any.
8517 this._mergeSettings(this.constructor.getDefaultConfig(), this.domElement.dataset, options, { rawValue : this.defaultRawValue });
8518 this.caretFix = false;
8519 this.throwInput = true; // Throw input event
8520 this.allowedTagList = AutoNumericEnum.allowedTagList;
8521 this.runOnce = false;
8522 this.hoveredWithAlt = false; // Keep tracks if the current AutoNumeric element is hovered by the mouse cursor while `Alt` is pressed
8523 }
8524
8525 // Modify the user settings to make them 'exploitable'
8526 this._transformOptionsValuesToDefaultTypes();
8527
8528 // Immediately run the callbacks that could update the settings object
8529 this._runCallbacksFoundInTheSettingsObject();
8530
8531 // Improve the `negativePositiveSignPlacement` option if needed
8532 this.constructor._correctNegativePositiveSignPlacementOption(this.settings);
8533
8534 // Set the `caretPositionOnFocus` and `selectOnFocus` options so that they do not conflict, if one of those have been set manually by the user.
8535 // If order to check that, we take a look at the original options the user passed as an argument, not `this.settings` that have been merged with the default settings. //TODO Check the validity of that comment
8536 this.constructor._correctCaretPositionOnFocusAndSelectOnFocusOptions(this.settings);
8537
8538 // Define if the negative or positive signs are allowed
8539 this.constructor._setNegativePositiveSignPermissions(this.settings);
8540
8541 // Calculate the number of decimal places (during the element initialization)
8542 if (!update) {
8543 // Make sure the `originalDecimalPlaces` info is set
8544 if (AutoNumericHelper.isNull(options) || !options.decimalPlaces) {
8545 this.settings.originalDecimalPlaces = null;
8546 } else {

Callers 4

constructorMethod · 0.95
updateMethod · 0.95
setMethod · 0.95
setUnformattedMethod · 0.95

Tested by

no test coverage detected