Skip to content

Commit

Permalink
fix some bugs, add suffix button to material input widget - version 0…
Browse files Browse the repository at this point in the history
….148
  • Loading branch information
madkne-laptop committed Nov 15, 2023
1 parent 7c7f91f commit b86aeb2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion data/templates/common/StrongFB-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class StrongFBValidator {
}

protected validateNumber(value: string) {
return /^\d+$/.test(String(value));
return /^\d+$/.test(String(value)) || value === '';
}

protected validateRequired(value: string | number, widgetName?: string) {
Expand Down
2 changes: 1 addition & 1 deletion data/templates/widgets/form-field/form-field.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class StrongFBFormFieldWidgetComponent extends StrongFBBaseWidget<FormFie
}, 5);

// =>listen on ngModelChange
this.formFieldInstance[0].instance['ngModelChange'].pipe(takeUntil(this.destroy$)).subscribe(it => this.changeFormFieldValue(it));
this.formFieldInstance[0].instance['ngModelChange'].pipe(takeUntil(this.destroy$)).subscribe(it => { if (it !== undefined) this.changeFormFieldValue(it) });
// =>listen on showChange
this.showChange.pipe(takeUntil(this.destroy$)).subscribe(it => {
// =>set show state
Expand Down
16 changes: 15 additions & 1 deletion data/templates/widgets/input/input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component, Output, EventEmitter } from '@angular/core';
import { StrongFBBaseWidget } from '../../common/StrongFB-widget';
import { InputSchema } from './input-interfaces';
import { syncSchema } from './convertor';
import { takeUntil } from 'rxjs';

@Component({
selector: 'input-widget',
Expand All @@ -22,6 +23,14 @@ export class StrongFBInputWidgetComponent extends StrongFBBaseWidget<InputSchema
this.schema = syncSchema(this.schema);

this.listenOnFormFieldChange('value');
// =>listen on value change
this.valueChanges$.pipe(takeUntil(this.destroy$)).subscribe(async (it: [boolean, any]) => {
if (!it || !it[0]) return;
this.schema.value = it[1];
if (it[1] === undefined || it[1] === null) {
this.changeValue();
}
});
}

normalizeSchema(schema: InputSchema) {
Expand All @@ -35,7 +44,7 @@ export class StrongFBInputWidgetComponent extends StrongFBBaseWidget<InputSchema
return schema;
}

changeValue(event) {
changeValue(event?) {
this.updateFormField('value');
}

Expand All @@ -49,4 +58,9 @@ export class StrongFBInputWidgetComponent extends StrongFBBaseWidget<InputSchema
break;
}
}

suffixButtonClick(e) {
if (!this.schema?._form?.suffixButton?.schema['click']) return;
this.schema?._form?.suffixButton?.schema['click'].call(this.widgetForm, e, this.schema?._form?.suffixButton);
}
}
6 changes: 6 additions & 0 deletions data/templates/widgets/input/material/input.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@
[placeholder]="schema.placeholder ? schema.placeholder : ''" [id]="widgetId" [(ngModel)]="schema.value"
(ngModelChange)="changeValue($event)" (keyup)="keyupEvent($event)" />
<span matSuffix *ngIf="schema?._form?.suffixText">{{schema?._form?.suffixText}}</span>
<!-- suffix button -->
<button *ngIf="schema?._form?.suffixButton && schema?._form?.suffixButton.schema?.mode == 'icon'" matSuffix
mat-icon-button (click)="suffixButtonClick()">
<icon-widget [icon]="schema?._form?.suffixButton.schema?.icon"></icon-widget>
</button>

</mat-form-field>
</ng-container>
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { error } from '@dat/lib/log';
import { UIFrameWorkType } from './types';


export const VERSION = '0.147';
export const VERSION = '0.148';

export async function detectAngularSourcePath() {
let cwdir = await cwd();
Expand Down

0 comments on commit b86aeb2

Please sign in to comment.