@projectcaluma/ember-form 14.10.1 → 14.10.3

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.
@@ -14,6 +14,7 @@
14
14
  value={{this.displayValue}}
15
15
  placeholder={{@field.question.raw.placeholder}}
16
16
  readonly={{this.disabled}}
17
+ {{on "keydown" this.checkInput}}
17
18
  {{on "input" this.input}}
18
19
  />
19
20
  {{/if}}
@@ -5,6 +5,10 @@ import { cached } from "tracked-toolbox";
5
5
 
6
6
  export default class CfFieldInputNumberSeparatorComponent extends Component {
7
7
  @service intl;
8
+ @service notification;
9
+
10
+ blockCount = 0;
11
+ blockNotified = false;
8
12
 
9
13
  get disabled() {
10
14
  return this.args.disabled || this.args.field?.question.isCalculated;
@@ -38,11 +42,57 @@ export default class CfFieldInputNumberSeparatorComponent extends Component {
38
42
  return this.intl.formatNumber(1.1).replace(/\p{Number}/gu, "");
39
43
  }
40
44
 
45
+ @cached
46
+ get allowedRegex() {
47
+ // Returns a regex for allowed input characters: digits and thousands
48
+ // separators for integers, plus decimal separators for floats.
49
+ const mil = RegExp.escape(this.thousandSeparator);
50
+ const dec = RegExp.escape(this.decimalSeparator);
51
+
52
+ if (this.args.field.questionType === "IntegerQuestion") {
53
+ return new RegExp(`(\\d|${mil})`);
54
+ }
55
+ return new RegExp(`(\\d|${mil}|${dec})`);
56
+ }
57
+
58
+ @action
59
+ checkInput(event) {
60
+ // allow keys like backspace, tab and arrows
61
+ if (event.key.length > 1 || event.ctrlKey || event.metaKey) {
62
+ return;
63
+ }
64
+
65
+ if (!this.allowedRegex.test(event.key)) {
66
+ event.preventDefault();
67
+ this.blockCount += 1;
68
+ }
69
+
70
+ // After the sixth attempt to enter a invalid character, the user will
71
+ // see a warning listing the characters that are allowed.
72
+ if (this.blockCount > 5 && !this.blockNotified) {
73
+ const allowedChars = ["0-9", this.thousandSeparator];
74
+
75
+ if (this.args.field.questionType === "FloatQuestion") {
76
+ allowedChars.push(this.decimalSeparator);
77
+ }
78
+
79
+ this.notification.warning(
80
+ this.intl.t(`caluma.form.validation.blockNotification`, {
81
+ allowedChars: allowedChars.join(" "),
82
+ }),
83
+ );
84
+
85
+ this.blockCount = 0;
86
+ this.blockNotified = true;
87
+ }
88
+ }
89
+
41
90
  @action
42
91
  input({ target: { value } }) {
43
92
  // We need to remove the thousand separator and replace the decimal
44
93
  // separator with a dot in order to parse it into a number. Which character
45
94
  // those are is determined per locale in the getters above.
95
+
46
96
  const serialized = parseFloat(
47
97
  value
48
98
  .replace(new RegExp(`\\${this.thousandSeparator}`, "g"), "")
@@ -66,9 +66,11 @@ export default class CfFieldInputTableComponent extends Component {
66
66
  );
67
67
 
68
68
  const owner = getOwner(this);
69
- const newDocument = new (owner.factoryFor("caluma-model:document").class)({
69
+ const Document = owner.factoryFor("caluma-model:document").class;
70
+ const newDocument = new Document({
70
71
  raw: this.parseDocument(raw),
71
72
  parentDocument: this.args.field.document,
73
+ parentField: this.args.field,
72
74
  owner,
73
75
  });
74
76
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@projectcaluma/ember-form",
3
- "version": "14.10.1",
3
+ "version": "14.10.3",
4
4
  "description": "Ember addon for rendering Caluma forms.",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -39,7 +39,7 @@
39
39
  "luxon": "^3.5.0",
40
40
  "reactiveweb": "^1.3.0",
41
41
  "tracked-toolbox": "^2.0.0",
42
- "@projectcaluma/ember-core": "^14.10.1"
42
+ "@projectcaluma/ember-core": "^14.10.3"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@ember/optional-features": "2.3.0",
@@ -74,12 +74,12 @@
74
74
  "uikit": "3.25.6",
75
75
  "uuid": "13.0.0",
76
76
  "webpack": "5.104.1",
77
- "@projectcaluma/ember-testing": "14.10.1",
78
- "@projectcaluma/ember-workflow": "14.10.1"
77
+ "@projectcaluma/ember-testing": "14.10.3",
78
+ "@projectcaluma/ember-workflow": "14.10.3"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "ember-source": ">= 4.0.0",
82
- "@projectcaluma/ember-workflow": "^14.10.1"
82
+ "@projectcaluma/ember-workflow": "^14.10.3"
83
83
  },
84
84
  "dependenciesMeta": {
85
85
  "@projectcaluma/ember-core": {
@@ -57,6 +57,7 @@ caluma:
57
57
  format: "{errorMsg}"
58
58
  table: "Mindestens eine Zeile der Tabelle wurde nicht korrekt ausgefüllt"
59
59
  error: "Folgende Fragen sind noch nicht korrekt ausgefüllt:"
60
+ blockNotification: "In diesem Feld sind nur folgende Zeichen erlaubt: {allowedChars}"
60
61
 
61
62
  compare:
62
63
  note: "Geändert von {username} am {date}"
@@ -57,6 +57,7 @@ caluma:
57
57
  format: "{errorMsg}"
58
58
  table: "At least one row of the table was not filled in correctly"
59
59
  error: "The following questions have not yet been filled in correctly:"
60
+ blockNotification: "Only the following characters are allowed in this field: {allowedChars}"
60
61
 
61
62
  compare:
62
63
  note: "Changed by {username} on {date}"
@@ -57,6 +57,7 @@ caluma:
57
57
  format: "{errorMsg}"
58
58
  table: "Au moins une ligne du tableau n'a pas été remplie correctement"
59
59
  error: "Les questions suivantes n'ont pas encore été correctement remplies :"
60
+ blockNotification: "Seuls les caractères suivants sont autorisés dans ce champ : {allowedChars}"
60
61
 
61
62
  compare:
62
63
  note: "Modifié par {username} le {date}"
@@ -57,6 +57,7 @@ caluma:
57
57
  format: "{errorMsg}"
58
58
  table: "Almeno una riga della tabella non è stata compilata correttamente."
59
59
  error: "Le domande seguenti non sono state compilate in modo corretto:"
60
+ blockNotification: "In questo campo sono consentiti solo i seguenti caratteri: {allowedChars}"
60
61
 
61
62
  compare:
62
63
  note: "Modificato da {username} il {date}"