Skip to content

Commit a62b6b4

Browse files
author
Tray2
committed
Fix functionality of addInputFieldBefore
1 parent dd93c35 commit a62b6b4

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

helper.js

+31-22
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,6 @@ function showMessageModal(modalType, message) {
9191
show(`${modalType}-modal`);
9292
}
9393

94-
async function getRequest(url, parameters = {}, loading = true) {
95-
try {
96-
if (loading) {
97-
showLoading();
98-
}
99-
let responsePromise = await fetch(url, { method: 'GET', headers: parameters});
100-
if(! responsePromise.ok) {
101-
if(loading) {
102-
hideLoading();
103-
}
104-
throw new Error(responsePromise.status );
105-
}
106-
if (loading) {
107-
hideLoading();
108-
}
109-
return await responsePromise.json();
110-
} catch (error) {
111-
return error;
112-
}
113-
}
114-
11594
function setFocusTo(selector) {
11695
getElement(selector).focus();
11796
}
@@ -145,7 +124,7 @@ function addInputFieldAfter(selector, attributes) {
145124

146125
function addInputFieldBefore(selector, attributes) {
147126
let element = createInput(attributes);
148-
getElement(selector).after(element);
127+
getElement(selector).before(element);
149128
}
150129

151130

@@ -160,6 +139,15 @@ function cloneInput(selector) {
160139
element.after(clone);
161140
}
162141

142+
function cloneElement(selector) {
143+
let element = getElement(selector);
144+
let clone = element.cloneNode();
145+
if (element.id !== undefined) {
146+
clone.id = element.id + Date.now();
147+
}
148+
element.after(clone);
149+
}
150+
163151
async function postRequest(url, parameters = {}, loading = true) {
164152
try {
165153
if (loading) {
@@ -186,3 +174,24 @@ async function postRequest(url, parameters = {}, loading = true) {
186174
return error;
187175
}
188176
}
177+
178+
async function getRequest(url, parameters = {}, loading = true) {
179+
try {
180+
if (loading) {
181+
showLoading();
182+
}
183+
let responsePromise = await fetch(url, { method: 'GET', headers: parameters});
184+
if(! responsePromise.ok) {
185+
if(loading) {
186+
hideLoading();
187+
}
188+
throw new Error(responsePromise.status );
189+
}
190+
if (loading) {
191+
hideLoading();
192+
}
193+
return await responsePromise.json();
194+
} catch (error) {
195+
return error;
196+
}
197+
}

0 commit comments

Comments
 (0)