@sealcode/sealgen 0.19.15 → 0.19.16

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.
@@ -21,6 +21,7 @@ class Tickable extends FormFieldControl {
21
21
  ];
22
22
  }
23
23
  async render(fctx) {
24
+ console.log("!! Rendering checkbox", this.field.name);
24
25
  const {
25
26
  parsed: _parsed,
26
27
  valid,
@@ -30,6 +31,8 @@ class Tickable extends FormFieldControl {
30
31
  fctx.data.raw_values,
31
32
  true
32
33
  );
34
+ const field_message = fctx.data.field_messages[this.field.name];
35
+ console.log(this.field.name, fctx.data.field_messages, field_message);
33
36
  const parsed = _parsed === null ? this.options.default_value : _parsed;
34
37
  const value = this.getValueAttribute(
35
38
  fctx.ctx,
@@ -72,7 +75,7 @@ class Tickable extends FormFieldControl {
72
75
  })();
73
76
  </script>
74
77
 
75
- ${~valid && !this.options.hide_errors && fctx.validate ? `<div class="input__error">${message}</div>` : ""}
78
+ ${(~valid || !!field_message) && !this.options.hide_errors && fctx.validate ? `<div class="input__error">${Array.from(new Set([message, field_message].filter((e) => !!e))).join(" \u2022 ")}</div>` : ""}
76
79
  `
77
80
  );
78
81
  }
package/lib/forms/form.js CHANGED
@@ -83,11 +83,16 @@ class Form extends MountableWithFields {
83
83
  }
84
84
  if (error instanceof SealiousErrors.FieldsError) {
85
85
  field_messages = Object.fromEntries(
86
- Object.entries(error.field_messages).map(([key, value]) => {
86
+ Object.entries(error.field_messages).filter(([key]) => key in this.fields).map(([key, value]) => {
87
87
  const message = value?.message || "";
88
88
  return [key, { type: "error", message }];
89
89
  })
90
90
  );
91
+ for (const [key, value] of Object.entries(error.field_messages)) {
92
+ if (!(key in this.fields)) {
93
+ error_message += " \xB7 " + value?.message;
94
+ }
95
+ }
91
96
  }
92
97
  const messages = [{ type: "error", text: error_message }];
93
98
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.19.15",
3
+ "version": "0.19.16",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -74,6 +74,7 @@ export abstract class Tickable<T> extends FormFieldControl {
74
74
  fctx.data.raw_values,
75
75
  true
76
76
  );
77
+ const field_message = fctx.data.field_messages[this.field.name];
77
78
  const parsed = _parsed === null ? this.options.default_value : _parsed;
78
79
 
79
80
  const value = this.getValueAttribute(
@@ -83,9 +84,9 @@ export abstract class Tickable<T> extends FormFieldControl {
83
84
  );
84
85
  const id = this.makeInputID(fctx.ctx, fctx.data.raw_values, parsed);
85
86
  const label =
86
- this.options.label != undefined
87
- ? this.options.label
88
- : this.field.name;
87
+ this.options.label != undefined ?
88
+ this.options.label
89
+ : this.field.name;
89
90
 
90
91
  const readonly = this.options.readonly || false;
91
92
  const required = this.field.required;
@@ -102,9 +103,9 @@ export abstract class Tickable<T> extends FormFieldControl {
102
103
  this.field.name}"
103
104
  ${value ? `value="${attribute(value)}"` : ""}
104
105
  ${fctx.form_id ? `form="${fctx.form_id}"` : ""}
105
- ${this.isChecked(fctx.ctx, fctx.data.raw_values, parsed)
106
- ? "checked"
107
- : ""}
106
+ ${this.isChecked(fctx.ctx, fctx.data.raw_values, parsed) ?
107
+ "checked"
108
+ : ""}
108
109
  ${readonly ? "readonly" : ""}
109
110
  ${required ? "required" : ""}
110
111
  autocomplete="off"
@@ -127,9 +128,13 @@ export abstract class Tickable<T> extends FormFieldControl {
127
128
  })();
128
129
  </script>
129
130
 
130
- ${~valid && !this.options.hide_errors && fctx.validate
131
- ? `<div class="input__error">${message}</div>`
132
- : ""}
131
+ ${(
132
+ (~valid || !!field_message) &&
133
+ !this.options.hide_errors &&
134
+ fctx.validate
135
+ ) ?
136
+ `<div class="input__error">${Array.from(new Set([message, field_message.message].filter((e) => !!e))).join(" • ")}</div>`
137
+ : ""}
133
138
  `
134
139
  );
135
140
  }
package/src/forms/form.ts CHANGED
@@ -136,11 +136,18 @@ export abstract class Form<
136
136
  }
137
137
  if (error instanceof SealiousErrors.FieldsError) {
138
138
  field_messages = Object.fromEntries(
139
- Object.entries(error.field_messages).map(([key, value]) => {
140
- const message = value?.message || "";
141
- return [key, { type: "error", message }];
142
- })
139
+ Object.entries(error.field_messages)
140
+ .filter(([key]) => key in this.fields)
141
+ .map(([key, value]) => {
142
+ const message = value?.message || "";
143
+ return [key, { type: "error", message }];
144
+ })
143
145
  );
146
+ for (const [key, value] of Object.entries(error.field_messages)) {
147
+ if (!(key in this.fields)) {
148
+ error_message += " · " + value?.message;
149
+ }
150
+ }
144
151
  }
145
152
  const messages = [<const>{ type: "error", text: error_message }];
146
153
  return {
@@ -1,13 +1,15 @@
1
+ /* eslint @typescript-eslint/no-unsafe-call: off, @typescript-eslint/no-unnecessary-type-assertion: off */
1
2
  import { Context } from "koa";
2
3
  import { Translation } from "sealious";
3
4
 
5
+ /** deprecated */
4
6
  export function t(
5
7
  ctx: Context,
6
8
  key: string,
7
- props: unknown[],
8
- default_translation: Translation
9
+ _props: unknown[],
10
+ _default_translation: Translation
9
11
  ) {
10
- return /* HTML */ `<span translation-key="${key.replace('"', '\\"')}"
11
- >${ctx.$app.getString(key, props, default_translation)}</span
12
- >`;
12
+ return /* HTML */ `<span translation-key="${key.replace('"', '\\"')}">
13
+ ${ctx.i18n`${key}`}
14
+ </span>`;
13
15
  }