@ideal-postcodes/jsutil
Advanced tools
Comparing version 7.2.0 to 7.3.0
@@ -233,6 +233,19 @@ "use strict"; | ||
if ((0, input_1.isSelect)(countyIso)) { | ||
if ((0, input_1.hasValue)(countyIso, countyIsoValue)) | ||
if ((0, input_1.hasValue)(countyIso, countyIsoValue)) { | ||
(0, input_1.change)({ e: countyIso, value: countyIsoValue }); | ||
if ((0, input_1.hasValue)(countyIso, countyValue || "")) | ||
} | ||
else if ((0, input_1.hasValue)(countyIso, countyValue || "")) { | ||
(0, input_1.change)({ e: countyIso, value: countyValue || "" }); | ||
} | ||
else { | ||
let text = (0, input_1.optionsHasText)(countyIso, countyValue); | ||
if (text.length > 0) { | ||
(0, input_1.change)({ e: countyIso, value: text[0].value || "" }); | ||
} | ||
else { | ||
text = (0, input_1.optionsHasText)(countyIso, countyIsoValue); | ||
if (text) | ||
(0, input_1.change)({ e: countyIso, value: text[0].value || "" }); | ||
} | ||
} | ||
} | ||
@@ -239,0 +252,0 @@ if ((0, input_1.isInput)(countyIso)) { |
@@ -40,3 +40,2 @@ "use strict"; | ||
const style = document.createElement("style"); | ||
style.type = "text/css"; | ||
style.appendChild(document.createTextNode(css)); | ||
@@ -43,0 +42,0 @@ document.head.appendChild(style); |
@@ -7,2 +7,3 @@ export declare const isSelect: (e: HTMLElement | null) => e is HTMLSelectElement; | ||
export declare const hasValue: (select: HTMLElement, value: string | null) => boolean; | ||
export declare const optionsHasText: (select: HTMLElement, value: string | null) => HTMLOptionElement[]; | ||
type InputElement = HTMLSelectElement | HTMLInputElement | HTMLTextAreaElement; | ||
@@ -9,0 +10,0 @@ interface SetValue { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.change = exports.setValue = exports.hasValue = exports.update = exports.isInputElem = exports.isTextarea = exports.isInput = exports.isSelect = void 0; | ||
exports.change = exports.setValue = exports.optionsHasText = exports.hasValue = exports.update = exports.isInputElem = exports.isTextarea = exports.isInput = exports.isSelect = void 0; | ||
const event_1 = require("./event"); | ||
@@ -40,2 +40,9 @@ const isSelect = (e) => { | ||
exports.hasValue = hasValue; | ||
const optionsHasText = (select, value) => { | ||
if (value === null) | ||
return []; | ||
const options = select.querySelectorAll("option"); | ||
return Array.from(options).filter((o) => o.textContent === value); | ||
}; | ||
exports.optionsHasText = optionsHasText; | ||
const updateSelect = ({ e, value, skipTrigger }) => { | ||
@@ -42,0 +49,0 @@ if (value === null) |
@@ -1,2 +0,2 @@ | ||
import { isInputElem, update, change, isSelect, isInput, hasValue, } from "./input"; | ||
import { isInputElem, update, change, isSelect, isInput, hasValue, optionsHasText, } from "./input"; | ||
import { toElem, contains } from "./dom"; | ||
@@ -219,6 +219,19 @@ import { updateCountry } from "./country"; | ||
if (isSelect(countyIso)) { | ||
if (hasValue(countyIso, countyIsoValue)) | ||
if (hasValue(countyIso, countyIsoValue)) { | ||
change({ e: countyIso, value: countyIsoValue }); | ||
if (hasValue(countyIso, countyValue || "")) | ||
} | ||
else if (hasValue(countyIso, countyValue || "")) { | ||
change({ e: countyIso, value: countyValue || "" }); | ||
} | ||
else { | ||
let text = optionsHasText(countyIso, countyValue); | ||
if (text.length > 0) { | ||
change({ e: countyIso, value: text[0].value || "" }); | ||
} | ||
else { | ||
text = optionsHasText(countyIso, countyIsoValue); | ||
if (text) | ||
change({ e: countyIso, value: text[0].value || "" }); | ||
} | ||
} | ||
} | ||
@@ -225,0 +238,0 @@ if (isInput(countyIso)) { |
@@ -33,3 +33,2 @@ const cache = {}; | ||
const style = document.createElement("style"); | ||
style.type = "text/css"; | ||
style.appendChild(document.createTextNode(css)); | ||
@@ -36,0 +35,0 @@ document.head.appendChild(style); |
@@ -7,2 +7,3 @@ export declare const isSelect: (e: HTMLElement | null) => e is HTMLSelectElement; | ||
export declare const hasValue: (select: HTMLElement, value: string | null) => boolean; | ||
export declare const optionsHasText: (select: HTMLElement, value: string | null) => HTMLOptionElement[]; | ||
type InputElement = HTMLSelectElement | HTMLInputElement | HTMLTextAreaElement; | ||
@@ -9,0 +10,0 @@ interface SetValue { |
@@ -31,2 +31,8 @@ import { trigger } from "./event"; | ||
}; | ||
export const optionsHasText = (select, value) => { | ||
if (value === null) | ||
return []; | ||
const options = select.querySelectorAll("option"); | ||
return Array.from(options).filter((o) => o.textContent === value); | ||
}; | ||
const updateSelect = ({ e, value, skipTrigger }) => { | ||
@@ -33,0 +39,0 @@ if (value === null) |
{ | ||
"name": "@ideal-postcodes/jsutil", | ||
"version": "7.2.0", | ||
"version": "7.3.0", | ||
"description": "Browser Address Autocomplete for api.ideal-postcodes.co.uk", | ||
@@ -5,0 +5,0 @@ "author": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92634
2578