MCPcopy
hub / github.com/autoNumeric/autoNumeric / _getParentForm

Method _getParentForm

src/AutoNumeric.js:3171–3204  ·  view source on GitHub ↗

* Returns a reference to the parent element if it exists, otherwise return `null`. * * @returns {HTMLFormElement|null} * @private

()

Source from the content-addressed store, hash-verified

3169 * @private
3170 */
3171 _getParentForm() {
3172 if (!AutoNumericHelper.isUndefined(this.domElement.form)) return this.domElement.form; // This catches input elements outside the form element
3173
3174 if (this.domElement.tagName.toLowerCase() === 'body') {
3175 return null;
3176 }
3177
3178 let node = this.domElement;
3179 let tagName;
3180 do {
3181 node = node.parentNode;
3182 if (AutoNumericHelper.isNull(node)) {
3183 // Special case when using templates with frameworks like Vue.js, where the input element can be 'detached' when initializing the DOM structure
3184 return null;
3185 }
3186
3187 if (node.tagName) {
3188 tagName = node.tagName.toLowerCase();
3189 } else {
3190 tagName = '';
3191 }
3192
3193 if (tagName === 'body') {
3194 // Get out of the loop if we get up to the `<body>` element
3195 break;
3196 }
3197 } while (tagName !== 'form');
3198
3199 if (tagName === 'form') {
3200 return node;
3201 } else {
3202 return null;
3203 }
3204 }
3205
3206 /**
3207 * Return a string in standard URL-encoded notation with the form input values being unformatted.

Callers 2

constructorMethod · 0.95
formMethod · 0.95

Calls 2

isUndefinedMethod · 0.80
isNullMethod · 0.80

Tested by

no test coverage detected