Skip to content

Commit 4514e31

Browse files
committed
Updated form
1 parent a0615fb commit 4514e31

File tree

5 files changed

+395
-467
lines changed

5 files changed

+395
-467
lines changed

js/form.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,11 @@ export default class Form extends View {
121121
elem.checked = true;
122122
}
123123
break;
124-
case 'select':
125-
if (elem.multiple) {
126-
elem.options.forEach((opt) => {
127-
// eslint-disable-next-line no-param-reassign
128-
opt.selected = this.constructor.$selected(opt.value, value);
129-
});
130-
} else {
124+
case 'select-multiple':
125+
Array.from(elem.options).forEach((option) => {
131126
// eslint-disable-next-line no-param-reassign
132-
elem.value = `${value}`;
133-
}
127+
option.selected = this.constructor.$selected(option.value, value);
128+
});
134129
break;
135130
default:
136131
// eslint-disable-next-line no-param-reassign
@@ -167,15 +162,11 @@ export default class Form extends View {
167162
values[key] = elem.value;
168163
}
169164
break;
170-
case 'select':
171-
if (elem.multiple) {
172-
values[key] = [];
173-
elem.selectedOptions.forEach((opt) => {
174-
values[key].push(opt.value);
175-
});
176-
} else {
177-
values[key] = elem.value;
178-
}
165+
case 'select-multiple':
166+
values[key] = [];
167+
Array.from(elem.selectedOptions).forEach((option) => {
168+
values[key].push(option.value);
169+
});
179170
break;
180171
default:
181172
values[key] = elem.value;

js/provider.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ export default class Provider extends Emitter {
147147
$fetch(url, req) {
148148
let status;
149149
let changed = false;
150-
this.dispatchEvent(EVENT_STARTED, this, this.$origin + (url || ''));
151-
fetch(this.$origin + url, req)
150+
let absurl = this.$origin + (url || '');
151+
if (!absurl.hasPrefix('/')) {
152+
absurl = `/${absurl}`;
153+
}
154+
this.dispatchEvent(EVENT_STARTED, this, absurl);
155+
fetch(absurl, req)
152156
.then((response) => {
153157
status = response;
154158
const contentType = response.headers ? response.headers.get('Content-Type') || '' : '';

js/string.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,15 @@ String.prototype.removePrefix = function (prefix) {
4444
const hasPrefix = this.indexOf(prefix) === 0;
4545
return hasPrefix ? this.substr(prefix.length) : this.toString();
4646
};
47+
48+
/**
49+
* @function hasPrefix
50+
* @memberof String
51+
* @description Check for prefix on a string.
52+
* @arg {string} prefix - The prefix to test for and remove
53+
* @returns boolean
54+
*/
55+
String.prototype.hasPrefix = function (prefix) {
56+
const hasPrefix = this.indexOf(prefix) === 0;
57+
return hasPrefix;
58+
};

0 commit comments

Comments
 (0)