* Return a reference to the parent element if it exists, otherwise return `null`. * If the parent form element as already been found, this directly return a reference to it. * However, you can force AutoNumeric to search again for its reference by passing `true` as a parameter to th
(forceSearch = false)
| 3097 | * @returns {HTMLFormElement|null} |
| 3098 | */ |
| 3099 | form(forceSearch = false) { |
| 3100 | if (forceSearch || AutoNumericHelper.isUndefinedOrNullOrEmpty(this.parentForm)) { |
| 3101 | const newParentForm = this._getParentForm(); |
| 3102 | if (!AutoNumericHelper.isNull(newParentForm) && newParentForm !== this.parentForm) { |
| 3103 | // If the current parent form exists and is different from the previous parent form |
| 3104 | |
| 3105 | // Search for all the AutoNumeric elements in the old parent form |
| 3106 | const oldANChildren = this._getFormAutoNumericChildren(this.parentForm); |
| 3107 | // Update the anCount with the correct number of AutoNumeric elements |
| 3108 | this.parentForm.dataset.anCount = oldANChildren.length; |
| 3109 | |
| 3110 | // Check if the new parent form already has a anFormHandler name |
| 3111 | if (this._hasFormHandlerFunction(newParentForm)) { |
| 3112 | this._incrementParentFormCounter(newParentForm); // Increment its counter |
| 3113 | } else { |
| 3114 | // Create one and set the anCount to 1 |
| 3115 | this._storeFormHandlerFunction(newParentForm); |
| 3116 | this._initializeFormCounterToOne(newParentForm); |
| 3117 | } |
| 3118 | } |
| 3119 | |
| 3120 | this.parentForm = newParentForm; |
| 3121 | } |
| 3122 | |
| 3123 | return this.parentForm; |
| 3124 | } |
| 3125 | |
| 3126 | /** |
| 3127 | * Returns an array of the AutoNumeric-managed elements for the given form element is passed, otherwise for the current `this.parentForm` element. |
no test coverage detected