Skip to content

Commit 640dbe7

Browse files
committed
Updated to v40 to add control method on form
1 parent 0e77548 commit 640dbe7

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

js/form.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export default class Form extends View {
5858
super(node);
5959
this.$modal = new ModalBS(node);
6060
this.$form = super.query('form');
61-
6261
if (!this.$form) {
6362
throw new Error('Form: Missing form element');
6463
}
@@ -105,6 +104,15 @@ export default class Form extends View {
105104
this.$modal.hide();
106105
}
107106

107+
/**
108+
* Return a named form control
109+
* @param {string} name - The name of the control.
110+
* @returns Node|undefined - The control or undefined if the named control does not exist.
111+
*/
112+
control(name) {
113+
return name ? this.$form.elements[name] : undefined;
114+
}
115+
108116
get formdata() {
109117
return new FormData(this.$form);
110118
}
@@ -135,22 +143,6 @@ export default class Form extends View {
135143
});
136144
}
137145

138-
static $selected(value, src) {
139-
if (src) {
140-
if (typeof src === 'string') {
141-
return value === src;
142-
}
143-
if (Array.isArray(src)) {
144-
for (let i = 0; i < src.length; i += 1) {
145-
if (this.$selected(value, src[i])) {
146-
return true;
147-
}
148-
}
149-
}
150-
}
151-
return false;
152-
}
153-
154146
get values() {
155147
const values = {};
156148
Array.from(this.$form.elements).forEach((elem) => {
@@ -176,4 +168,20 @@ export default class Form extends View {
176168
});
177169
return values;
178170
}
171+
172+
static $selected(value, src) {
173+
if (src) {
174+
if (typeof src === 'string') {
175+
return value === src;
176+
}
177+
if (Array.isArray(src)) {
178+
for (let i = 0; i < src.length; i += 1) {
179+
if (this.$selected(value, src[i])) {
180+
return true;
181+
}
182+
}
183+
}
184+
}
185+
return false;
186+
}
179187
}

js/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default class View extends Emitter {
7575
* @throws {Error}
7676
*/
7777
replace(selector, ...args) {
78-
const node = this.query(selector);
78+
const node = selector ? this.query(selector) : this.$node;
7979
if (!node) {
8080
throw new Error(`View: Invalid selector ${selector}`);
8181
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@djthorpe/js-framework",
3-
"version": "0.0.39",
3+
"version": "0.0.40",
44
"description": "Javascript Framework",
55
"main": "dist/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)