Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,12 @@ export class DbTableWidgetsComponent implements OnInit {
// isCurrency, isBtcAddress, isISO8601, isISO31661Alpha2, isISO31661Alpha3, isISO4217,
// isDataURI, isMagnetURI, isMimeType, isLatLong, isSlug, isStrongPassword, isTaxID, isVAT
// OR use "regex" with a regex parameter for custom pattern matching
// force_send_empty_string: when true, always send "" to the backend on clear,
// even if the column is nullable. Default false (cleared input becomes NULL on nullable columns).
{
"validate": null,
"regex": null
"regex": null,
"force_send_empty_string": false
}`,
Textarea: `// provide number of strings to show.
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
[validateType]="validateType"
[regexPattern]="regexPattern"
attr.data-testid="record-{{label()}}-text"
[(ngModel)]="value" (ngModelChange)="onFieldChange.emit($event)">
@if (maxLength && maxLength > 0 && value() && (maxLength - value().length) < 100) {
[(ngModel)]="value" (ngModelChange)="handleValueChange($event)">
@if (maxLength && maxLength > 0 && value() && 100 > (maxLength - value().length)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Restore the < form to silence HTMLHint and improve readability.

Flipping the comparison to 100 > (maxLength - value().length) makes HTMLHint flag the > as an unescaped special character (twice on this line). The previous form (maxLength - value().length) < 100 is semantically identical, avoids the lint error, and reads more naturally as "remaining chars below threshold."

🛠 Proposed fix
-    `@if` (maxLength && maxLength > 0 && value() && 100 > (maxLength - value().length)) {
+    `@if` (maxLength && maxLength > 0 && value() && (maxLength - value().length) < 100) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@if (maxLength && maxLength > 0 && value() && 100 > (maxLength - value().length)) {
`@if` (maxLength && maxLength > 0 && value() && (maxLength - value().length) < 100) {
🧰 Tools
🪛 HTMLHint (1.9.2)

[error] 12-12: Special characters must be escaped : [ > ].

(spec-char-escape)


[error] 12-12: Special characters must be escaped : [ > ].

(spec-char-escape)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@frontend/src/app/components/ui-components/record-edit-fields/text/text.component.html`
at line 12, The conditional expression in the template uses a flipped comparison
"100 > (maxLength - value().length)" which triggers HTMLHint for an unescaped
'>' and reduces readability; change it back to the previous form "(maxLength -
value().length) < 100" inside the same conditional (the line referencing
maxLength and value()) to silence the linter and restore clear "remaining chars
below threshold" semantics.

Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The counter threshold condition uses a “Yoda-style” comparison (100 > ...), which is inconsistent with similar widgets (e.g., long-text uses (maxLength - value().length) < 100). Consider switching back to the existing style for consistency/readability.

Suggested change
@if (maxLength && maxLength > 0 && value() && 100 > (maxLength - value().length)) {
@if (maxLength && maxLength > 0 && value() && (maxLength - value().length) < 100) {

Copilot uses AI. Check for mistakes.
<div matSuffix class="counter">{{value().length}} / {{maxLength}}</div>
}
@if (textField.errors?.['required']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ describe('TextEditComponent', () => {
});

it('should parse regexPattern from widget params', () => {
fixture.componentRef.setInput('widgetStructure', { widget_params: { validate: 'regex', regex: '^[a-z]+$' } } as any);
fixture.componentRef.setInput('widgetStructure', {
widget_params: { validate: 'regex', regex: '^[a-z]+$' },
} as any);
component.ngOnInit();
expect(component.regexPattern).toBe('^[a-z]+$');
});
Expand Down Expand Up @@ -80,4 +82,49 @@ describe('TextEditComponent', () => {
component.validateType = 'customValidator';
expect(component.getValidationErrorMessage()).toBe('Invalid customValidator');
});

it('should default forceSendEmptyString to false when widget_params omits the key', () => {
fixture.componentRef.setInput('widgetStructure', { widget_params: { validate: null, regex: null } } as any);
component.ngOnInit();
expect(component.forceSendEmptyString).toBe(false);
});

it('should emit null on empty input when column is nullable and force_send_empty_string is not set', () => {
fixture.componentRef.setInput('structure', { allow_null: true } as any);
component.ngOnInit();
const emitted: any[] = [];
component.onFieldChange.subscribe((v) => emitted.push(v));
component.handleValueChange('');
expect(emitted).toEqual([null]);
});

it('should emit empty string on empty input when column is not nullable', () => {
fixture.componentRef.setInput('structure', { allow_null: false } as any);
component.ngOnInit();
const emitted: any[] = [];
component.onFieldChange.subscribe((v) => emitted.push(v));
component.handleValueChange('');
expect(emitted).toEqual(['']);
});

it('should emit empty string on empty input when force_send_empty_string is true even on nullable column', () => {
fixture.componentRef.setInput('structure', { allow_null: true } as any);
fixture.componentRef.setInput('widgetStructure', {
widget_params: { force_send_empty_string: true },
} as any);
component.ngOnInit();
const emitted: any[] = [];
component.onFieldChange.subscribe((v) => emitted.push(v));
component.handleValueChange('');
expect(emitted).toEqual(['']);
});

it('should emit non-empty value unchanged regardless of nullability', () => {
fixture.componentRef.setInput('structure', { allow_null: true } as any);
component.ngOnInit();
const emitted: any[] = [];
component.onFieldChange.subscribe((v) => emitted.push(v));
component.handleValueChange('hello');
expect(emitted).toEqual(['hello']);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class TextEditComponent extends BaseEditFieldComponent implements OnInit
maxLength: number | null = null;
validateType: string | null = null;
regexPattern: string | null = null;
forceSendEmptyString: boolean = false;

override ngOnInit(): void {
super.ngOnInit();
Expand All @@ -35,9 +36,18 @@ export class TextEditComponent extends BaseEditFieldComponent implements OnInit

this.validateType = params.validate || null;
this.regexPattern = params.regex || null;
this.forceSendEmptyString = !!params.force_send_empty_string;
}
}

handleValueChange(v: string | null): void {
if (v === '' && !this.forceSendEmptyString && this.structure()?.allow_null === true) {
this.onFieldChange.emit(null);
return;
}
this.onFieldChange.emit(v);
}

getValidationErrorMessage(): string {
if (!this.validateType) {
return '';
Expand Down
Loading