Skip to content

Commit

Permalink
fix(core): submit buttons leads to refresh in firefox (#608)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Sielemann <[email protected]>
  • Loading branch information
TimSielemann and Tim Sielemann authored Nov 28, 2024
1 parent 3894b41 commit 1a1f600
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions angular/projects/catalyst-demo/src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ <h1>new datetime picker</h1>
<span slot="hint">Hint</span>
</cat-tag>
</form>
<form class="cat-p-l" (ngSubmit)="submitIt($event)">
<cat-button [submit]="true">TEST SUBMIT</cat-button>
</form>
4 changes: 4 additions & 0 deletions angular/projects/catalyst-demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ export class AppComponent implements OnInit {
logChanges($event: any) {
console.log($event);
}

submitIt($event: any) {
console.log('hello', $event);
}
}
5 changes: 3 additions & 2 deletions angular/projects/catalyst-demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { CatalystModule } from '@haiilo/catalyst-angular';
import { FormlyModule } from '@ngx-formly/core';
Expand All @@ -14,7 +14,8 @@ import { DialogComponent } from './dialog/dialog.component';
FormlyModule.forRoot(),
CatalystModule.forRoot(),
CatalystFormlyModule,
CatalystModule
CatalystModule,
FormsModule
],
declarations: [AppComponent, DialogComponent],
bootstrap: [AppComponent]
Expand Down
5 changes: 4 additions & 1 deletion core/src/components/cat-button/cat-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,10 @@ export class CatButton {
event.stopImmediatePropagation();
} else if (this.submit) {
const form = findClosest('form', this.hostElement);
form?.dispatchEvent(new SubmitEvent('submit', { submitter: this.button }));
const event = new SubmitEvent('submit', { submitter: this.button, cancelable: true });
form?.dispatchEvent(event);
event.stopPropagation();
event.preventDefault();
}
}

Expand Down

0 comments on commit 1a1f600

Please sign in to comment.