Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal filter reset #1563

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -93,7 +93,8 @@
</div>

<div *ngIf="showReset" class="horizontal-reset margin-left-2 text-right">
<sds-formly-reset [options]="options" [defaultModel]="{}" (resetClicked)="resetClicked.emit()"></sds-formly-reset>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is changing what events are being emitted. resetClicked is no longer being emitted and filterChange is now being emitted when reset is clicked.

<sds-formly-reset [options]="options" [defaultModel]="defaultModel" (resetClicked)="reset($event)">
</sds-formly-reset>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ export class SdsFiltersComponent implements OnInit, OnChanges {
this.updateChange(change);
}

clearSearchContent() {
this.model['searchModel'] = '';
this.updateChange(this.model);
}

reset(isOptionsEmpty: boolean) {
if (isOptionsEmpty) {
this.clearSearchContent();
}
}

onResetClicked() {
const fieldChangeEvent: FormlyValueChangeEvent = {
field: { key: '' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ export class SdsFormlyResetComponent {
@Output() resetClicked = new EventEmitter();

resetAll() {
if (this.defaultModel) {
this.options.resetModel(this.defaultModel);
if (Object.keys(this.options).length === 0) {
this.resetClicked.emit(true);
} else {
this.options.resetModel();
if (this.defaultModel) {
this.options.resetModel(this.defaultModel);
} else {
this.options.resetModel();
}
this.resetClicked.emit(false);
}
this.resetClicked.emit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class FormlyUtilsService {
) {
if (field.props && (options.convertAll || Object.values(SdsReadonlyTypes).includes(field.type as any))) {
const label = field.props.label;
const value = model[field.key as string];
const value = model ? model[field.key as string] : {};
const readonlyOptions: ReadonlyOptions = {
providedOptions: field.props.options as any,
autocompleteOptions: field.props.configuration,
Expand All @@ -84,8 +84,8 @@ export class FormlyUtilsService {

if (field.type === SdsFormlyTypes.DATERANGEPICKER || field.type === SdsFormlyTypes.DATERANGEPICKERV2) {
readonlyOptions.daterangepickerOptions = {
fromDateKey: field.fieldGroup[0].key as string,
toDateKey: field.fieldGroup[1].key as string,
fromDateKey: field.fieldGroup ? (field.fieldGroup[0].key as string) : (field.key as string),
toDateKey: field.fieldGroup ? (field.fieldGroup[1].key as string) : (field.key as string),
};
return;
}
Expand Down