Skip to content

Commit aff393d

Browse files
committed
primeng: toggle wrapper
* Fixes the default value for the array in the editor. Co-Authored-by: Johnny Mariéthoz <[email protected]>
1 parent b411a76 commit aff393d

File tree

3 files changed

+9
-27
lines changed

3 files changed

+9
-27
lines changed

projects/rero/ng-core/assets/scss/_theme.scss

+2-20
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ a:hover:not(.p-button):not(.p-element):not([role=button]):not([role=tab]) {
4444
dl.metadata {
4545
@extend .grid, .my-0, .w-full, .p-2;
4646
dt {
47-
@extend .font-bold, .col-12, .py-0;
47+
@extend .font-bold, .col-12, .py-0, .mx-0, .my-1;
4848
@include styleclass('md:col-4');
4949
}
5050
dd {
51-
@extend .col-12, .py-0, .m-0;
51+
@extend .col-12, .py-0, .mx-0, .my-1;
5252
@include styleclass('md:col-8');
5353
}
5454
}
@@ -66,21 +66,3 @@ legend {
6666
@extend .text-base;
6767
width: auto;
6868
}
69-
70-
// CALLOUT
71-
.callout {
72-
border: 1px solid var(--surface-300);
73-
border-left: 5px solid var(--surface-300);
74-
border-radius: 5px;
75-
}
76-
77-
@each $variant in $callout-variants {
78-
.callout-#{$variant} {
79-
border: 1px solid rgba(var(--callout-color-#{$variant}), 0.3);
80-
border-left: 5px solid rgb(var(--callout-color-#{$variant}));
81-
}
82-
83-
.callout-bg-#{$variant} {
84-
background-color: rgba(var(--callout-color-#{$variant}), 0.05);
85-
}
86-
}

projects/rero/ng-core/src/lib/record/editor/services/jsonschema.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class JSONSchemaService {
4545
processField(field: FormlyFieldConfig, jsonSchema: JSONSchema7) {
4646
// initial population of arrays with a minItems constraints
4747
if (field.type === 'array' && jsonSchema.minItems && !jsonSchema.hasOwnProperty('default')) {
48-
field.defaultValue = new Array(jsonSchema.minItems);
48+
field.defaultValue = new Array(jsonSchema.minItems).fill(null);
4949
}
5050
// If 'format' is defined into the jsonSchema, use it as props to try a validation on this field.
5151
// See: `email.validator.ts` file

projects/rero/ng-core/src/lib/record/editor/wrappers/toggle-wrapper/toggle-wrappers.component.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,16 @@ import { isEmpty, removeEmptyValues } from '../../utils';
2121
@Component({
2222
selector: 'ng-core-editor-formly-toggle-wrapper',
2323
template: `
24-
<div class='toggle-wrapper'>
25-
<div class="custom-control custom-switch">
26-
<input class="custom-control-input" type="checkbox" id="toggle-switch-{{ field.id }}"
27-
(change)="toggle($event)" [checked]="tsOptions.enabled">
24+
<div class="flex gap-2">
25+
<p-inputSwitch id="toggle-switch-{{ field.id }}"
26+
(onChange)="toggle($event)" [ngModel]="tsOptions.enabled" />
2827
<label class="custom-control-label" for="toggle-switch-{{ field.id }}"
2928
[pTooltip]="tsOptions.description|translate" tooltipPosition="top"
3029
>{{ tsOptions.label | translate }}</label>
3130
</div>
3231
@if (tsOptions.enabled) {
3332
<ng-container #fieldComponent></ng-container>
3433
}
35-
</div>
3634
`
3735
})
3836
export class ToggleWrapperComponent extends FieldWrapper implements OnInit {
@@ -72,10 +70,12 @@ export class ToggleWrapperComponent extends FieldWrapper implements OnInit {
7270

7371
toggle(event: any) {
7472
if (this.tsOptions.enabled === true) {
73+
// if (event.checked === false) {
7574
// toggle switch will became 'false', so just reset the field.
7675
// Resetting the field will change its value and so the `valueChanges` Observer will be called. The toggle `enabled` value will
7776
// be update (to false) by this method.
78-
this.field.formControl.reset(); // reset all children fields
77+
this.field.formControl.setErrors(null);
78+
this.field.formControl.reset(this.field.defaultValue); // reset all children fields
7979
} else {
8080
this.tsOptions.enabled = true;
8181
this.field.formControl.enable({emitEvent: false});

0 commit comments

Comments
 (0)