Skip to content

Commit

Permalink
Merge branch 'main' into main-v16
Browse files Browse the repository at this point in the history
# Conflicts:
#	projects/klippa/ngx-enhancy-forms/package.json
  • Loading branch information
MarkDoggen committed Jul 31, 2024
2 parents 8c1536a + dea3dde commit 3a3e385
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions projects/demo/src/app/demo/demo.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<klp-form [formGroup]="myForm" [warnings]="formWarnings" errorMessageLocation="rightOfCaption" [readOnly]="false">
<klp-form [formGroup]="myForm" [warnings]="formWarnings" errorMessageLocation="rightOfCaption" [readOnly]="false" allowSubmitOn="buttonOnly">
<div style="height: 520px; overflow: auto; display: flex; gap: 30px">
<app-deep-input *ngIf="false" >
</app-deep-input>
Expand Down Expand Up @@ -211,7 +211,7 @@

simple form with form level errors

<klp-form [formGroup]="simpleFormWithFormLevelErrors" [errors]="formErrors" errorMessageLocation="rightOfCaption">
<klp-form [formGroup]="simpleFormWithFormLevelErrors" [errors]="formErrors" errorMessageLocation="rightOfCaption" allowSubmitOn="buttonOnly">
<klp-form-element caption="First name" spaceDistribution="34-66" direction="vertical">
<klp-form-text-input formControlName="firstName" [clearable]="true">
</klp-form-text-input>
Expand Down
8 changes: 4 additions & 4 deletions projects/klippa/ngx-enhancy-forms/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@klippa/ngx-enhancy-forms",
"version": "16.22.13",
"version": "16.22.14",
"publishConfig": {
"access": "public"
},
"peerDependencies": {
"@angular/common": ">=16",
"@angular/core": ">=16",
"@angular/common": ">=10",
"@angular/core": ">=10",
"@ng-select/ng-select": ">=9",
"ngx-mat-datefns-date-adapter": ">=10",
"date-fns": ">=2.29",
"lodash-es": ">=4.17",
"@dustfoundation/ngx-sortablejs": ">=15.0.0",
"ngx-sortablejs": ">=11.1",
"sortablejs": ">=1.15"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[disabled]="isLoading || disabled"
[isLoading]="isLoading"
[fullWidth]="fullWidth"
type="submit"
[type]="buttonType"
[ngClass]="fullWidth ? 'fullWidth' : ''"
>
<ng-content></ng-content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, HostBinding, inject, Input } from '@angular/core';
import {Component, HostBinding, inject, Input, OnInit} from '@angular/core';
import {FormComponent, invalidFieldsSymbol} from '../form.component';
import { ButtonVariant } from '../../elements/button/button.component';
import { DefaultErrorHandler, FormValidationError, KLP_FORM_ERROR_HANDLER } from '../form-validation-error/form-validation-error';
Expand All @@ -15,9 +15,10 @@ export type SubmitButtonVariant = Extract<ButtonVariant,
templateUrl: './form-submit-button.component.html',
styleUrls: ['./form-submit-button.component.scss'],
})
export class FormSubmitButtonComponent {
export class FormSubmitButtonComponent implements OnInit{
private parentForm = inject(FormComponent, {optional: true});
private handleError = inject(KLP_FORM_ERROR_HANDLER, {optional: true}) ?? DefaultErrorHandler;
public buttonType: 'submit' | 'button' = 'submit';

@Input() public isLoading = false;
@Input() @HostBinding('class._fullWidth') public fullWidth = false;
Expand All @@ -27,6 +28,14 @@ export class FormSubmitButtonComponent {
@Input() public after: () => Promise<any> = () => Promise.resolve();
@Input() public disabled: boolean = false;

ngOnInit(): void {
if (this.parentForm.allowSubmitOn === 'buttonOnly') {
this.buttonType = 'button';
} else {
this.buttonType = 'submit';
}
}

private setValidationError = (e: FormValidationError) => {
this.parentForm.formGroup.get(e.path)?.setErrors({ message: { value: e.message }});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class FormComponent implements OnInit, OnDestroy, OnChanges {
@Input() public warnings: Map<AbstractControl, string | TemplateRef<any>> = new Map<AbstractControl, string | TemplateRef<any>>();
@Input() public errors: Map<AbstractControl, string> = new Map<AbstractControl, string>();
@Input() public patchValueInterceptor: (values: any) => Promise<any>;
@Input() public allowSubmitOn: 'buttonAndEnter' | 'buttonOnly' = 'buttonAndEnter';
@Output() public onInjected = new EventEmitter<Record<string, any>>();

// we keep track of what form controls are actually rendered. Only those count when looking at form validation
Expand Down

0 comments on commit 3a3e385

Please sign in to comment.