@sealcode/sealgen 0.15.19 → 0.15.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/src/forms/controls/checkbox.d.ts +2 -0
- package/@types/src/forms/fields/collection-field.test.d.ts +1 -0
- package/lib/forms/controls/checkbox.js +6 -2
- package/lib/forms/fields/field.js +1 -1
- package/lib/forms/fields/field.test.js +40 -0
- package/lib/forms/form.js +1 -0
- package/package.json +1 -1
- package/src/forms/controls/checkbox.ts +13 -0
- package/src/forms/fields/field.test.ts +46 -1
- package/src/forms/fields/field.ts +1 -1
- package/src/forms/form.ts +1 -0
|
@@ -3,7 +3,9 @@ import { FormDataValue } from "../form-types.js";
|
|
|
3
3
|
import { Tickable, TickableOptions } from "./tickable.js";
|
|
4
4
|
import { FormField } from "../fields/field.js";
|
|
5
5
|
export declare class Checkbox extends Tickable<boolean> {
|
|
6
|
+
field: FormField<boolean, boolean>;
|
|
6
7
|
type: "checkbox";
|
|
8
|
+
constructor(field: FormField<boolean, boolean>, options?: Partial<TickableOptions<boolean>>);
|
|
7
9
|
isChecked(_ctx: Context, _data: Record<string, FormDataValue>, value: boolean): boolean;
|
|
8
10
|
getValueAttribute(): string;
|
|
9
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { Tickable } from "./tickable.js";
|
|
2
2
|
class Checkbox extends Tickable {
|
|
3
|
-
constructor() {
|
|
4
|
-
super(
|
|
3
|
+
constructor(field, options = {}) {
|
|
4
|
+
super(field, {
|
|
5
|
+
...options,
|
|
6
|
+
default_value: options.default_value == void 0 ? false : options.default_value
|
|
7
|
+
});
|
|
8
|
+
this.field = field;
|
|
5
9
|
this.type = "checkbox";
|
|
6
10
|
}
|
|
7
11
|
isChecked(_ctx, _data, value) {
|
|
@@ -7,6 +7,8 @@ import { getBrowser } from "../../utils/browser-creator.js";
|
|
|
7
7
|
import assert from "assert";
|
|
8
8
|
import { SimpleFormField } from "./simple-form-field.js";
|
|
9
9
|
import { SimpleInput } from "../controls/simple-input.js";
|
|
10
|
+
import { Boolean } from "./boolean.js";
|
|
11
|
+
import { Checkbox } from "../controls/checkbox.js";
|
|
10
12
|
describe("basic field", () => {
|
|
11
13
|
describe("basic tests", async () => {
|
|
12
14
|
let server;
|
|
@@ -100,6 +102,44 @@ describe("basic field", () => {
|
|
|
100
102
|
assert(is_value_valid_called == false);
|
|
101
103
|
assert(parse_called == false);
|
|
102
104
|
});
|
|
105
|
+
it("Accepts a form where non-required values are empty", async () => {
|
|
106
|
+
const port = await getPort();
|
|
107
|
+
console.log(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
108
|
+
const app = new Koa();
|
|
109
|
+
const router = new Router();
|
|
110
|
+
let submit_called = false;
|
|
111
|
+
const fields = {
|
|
112
|
+
text: new SimpleFormField(false),
|
|
113
|
+
checkbox: new Boolean(false)
|
|
114
|
+
};
|
|
115
|
+
mount(
|
|
116
|
+
router,
|
|
117
|
+
"/",
|
|
118
|
+
new class extends Form {
|
|
119
|
+
constructor() {
|
|
120
|
+
super(...arguments);
|
|
121
|
+
this.fields = fields;
|
|
122
|
+
this.controls = [new SimpleInput(fields.text), new Checkbox(fields.checkbox)];
|
|
123
|
+
}
|
|
124
|
+
async onSubmit() {
|
|
125
|
+
submit_called = true;
|
|
126
|
+
}
|
|
127
|
+
async canAccess(_) {
|
|
128
|
+
return { canAccess: true, message: "" };
|
|
129
|
+
}
|
|
130
|
+
}(),
|
|
131
|
+
true
|
|
132
|
+
);
|
|
133
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
134
|
+
server = app.listen(port);
|
|
135
|
+
browser = await getBrowser();
|
|
136
|
+
const context = await browser.newContext();
|
|
137
|
+
page = await context.newPage();
|
|
138
|
+
await page.goto(`http://localhost:${port}`);
|
|
139
|
+
await page.getByRole("button", { name: "Wy\u015Blij" }).click();
|
|
140
|
+
assert(submit_called, "onSubmit() triggered");
|
|
141
|
+
await page.getByText("Done").click();
|
|
142
|
+
});
|
|
103
143
|
});
|
|
104
144
|
});
|
|
105
145
|
//# sourceMappingURL=field.test.js.map
|
package/lib/forms/form.js
CHANGED
package/package.json
CHANGED
|
@@ -6,6 +6,19 @@ import { FormField } from "../fields/field.js";
|
|
|
6
6
|
export class Checkbox extends Tickable<boolean> {
|
|
7
7
|
type = <const>"checkbox";
|
|
8
8
|
|
|
9
|
+
constructor(
|
|
10
|
+
public field: FormField<boolean, boolean>,
|
|
11
|
+
options: Partial<TickableOptions<boolean>> = {}
|
|
12
|
+
) {
|
|
13
|
+
super(field, {
|
|
14
|
+
...options,
|
|
15
|
+
default_value:
|
|
16
|
+
options.default_value == undefined
|
|
17
|
+
? false
|
|
18
|
+
: options.default_value,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
9
22
|
isChecked(
|
|
10
23
|
_ctx: Context,
|
|
11
24
|
_data: Record<string, FormDataValue>,
|
|
@@ -10,7 +10,8 @@ import assert from "assert";
|
|
|
10
10
|
import { SimpleFormField } from "./simple-form-field.js";
|
|
11
11
|
import { SimpleInput } from "../controls/simple-input.js";
|
|
12
12
|
import { FormData } from "../form-types.js";
|
|
13
|
-
import {
|
|
13
|
+
import { Boolean } from "./boolean.js";
|
|
14
|
+
import { Checkbox } from "../controls/checkbox.js";
|
|
14
15
|
|
|
15
16
|
describe("basic field", () => {
|
|
16
17
|
describe("basic tests", async () => {
|
|
@@ -116,5 +117,49 @@ describe("basic field", () => {
|
|
|
116
117
|
assert(is_value_valid_called == false);
|
|
117
118
|
assert(parse_called == false);
|
|
118
119
|
});
|
|
120
|
+
|
|
121
|
+
it("Accepts a form where non-required values are empty", async () => {
|
|
122
|
+
const port = await getPort();
|
|
123
|
+
console.log(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
124
|
+
const app = new Koa();
|
|
125
|
+
const router = new Router();
|
|
126
|
+
|
|
127
|
+
let submit_called = false;
|
|
128
|
+
|
|
129
|
+
const fields = {
|
|
130
|
+
text: new SimpleFormField(false),
|
|
131
|
+
checkbox: new Boolean(false),
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
mount(
|
|
135
|
+
router,
|
|
136
|
+
"/",
|
|
137
|
+
new (class extends Form<typeof fields, unknown> {
|
|
138
|
+
fields = fields;
|
|
139
|
+
controls = [new SimpleInput(fields.text), new Checkbox(fields.checkbox)];
|
|
140
|
+
|
|
141
|
+
async onSubmit() {
|
|
142
|
+
submit_called = true;
|
|
143
|
+
//noop
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async canAccess(_: Context) {
|
|
147
|
+
return { canAccess: true, message: "" };
|
|
148
|
+
}
|
|
149
|
+
})(),
|
|
150
|
+
true
|
|
151
|
+
);
|
|
152
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
153
|
+
server = app.listen(port);
|
|
154
|
+
|
|
155
|
+
browser = await getBrowser();
|
|
156
|
+
const context = await browser.newContext();
|
|
157
|
+
page = await context.newPage();
|
|
158
|
+
await page.goto(`http://localhost:${port}`);
|
|
159
|
+
await page.getByRole("button", { name: "Wyślij" }).click();
|
|
160
|
+
|
|
161
|
+
assert(submit_called, "onSubmit() triggered");
|
|
162
|
+
await page.getByText("Done").click();
|
|
163
|
+
});
|
|
119
164
|
});
|
|
120
165
|
});
|
|
@@ -130,7 +130,7 @@ export abstract class FormField<
|
|
|
130
130
|
if (raw == undefined || raw == null || raw == "") {
|
|
131
131
|
return {
|
|
132
132
|
parsed: null,
|
|
133
|
-
message: "empty value",
|
|
133
|
+
message: this.required ? "empty value" : "",
|
|
134
134
|
raw,
|
|
135
135
|
...(validate ? { valid: !this.required } : {}),
|
|
136
136
|
};
|