MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / promptCreateInput

Function promptCreateInput

external_resource/prompt/page/prompt.js:195–228  ·  view source on GitHub ↗
(options)

Source from the content-addressed store, hash-verified

193
194//creates input box
195function promptCreateInput(options) {
196 const dataElement = document.createElement("input");
197 dataElement.setAttribute("type", "text");
198
199 dataElement.value = options.value ?? "";
200
201 //insert custom input attributes if in options
202 if (options.inputAttrs && typeof options.inputAttrs === "object") {
203 for (const k in options.inputAttrs) {
204 if (!Object.prototype.hasOwnProperty.call(options.inputAttrs, k)) {
205 continue;
206 }
207
208 dataElement.setAttribute(k, options.inputAttrs[k]);
209 }
210 }
211
212 //Cancel/Exit on 'Escape'
213 dataElement.addEventListener("keyup", (event) => {
214 if (event.key === "Escape") {
215 promptCancel();
216 }
217 });
218
219 //Confirm on 'Enter'
220 dataElement.addEventListener("keypress", (event) => {
221 if (event.key === "Enter") {
222 event.preventDefault();
223 $("#ok").click();
224 }
225 });
226
227 return dataElement;
228}
229
230//add many inputs to container element
231function promptCreateMultiInput(parentElement) {

Callers 3

promptRegisterFunction · 0.85
promptCreateMultiInputFunction · 0.85
promptCreateCounterFunction · 0.85

Calls 3

promptCancelFunction · 0.85
$Function · 0.85
callMethod · 0.80

Tested by

no test coverage detected