Skip to content

Commit 2f29941

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

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

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

+2-2
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
}

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

+5-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 {
@@ -75,7 +73,8 @@ export class ToggleWrapperComponent extends FieldWrapper implements OnInit {
7573
// toggle switch will became 'false', so just reset the field.
7674
// Resetting the field will change its value and so the `valueChanges` Observer will be called. The toggle `enabled` value will
7775
// be update (to false) by this method.
78-
this.field.formControl.reset(); // reset all children fields
76+
this.field.formControl.setErrors(null);
77+
this.field.formControl.reset(this.field.defaultValue); // reset all children fields
7978
} else {
8079
this.tsOptions.enabled = true;
8180
this.field.formControl.enable({emitEvent: false});

0 commit comments

Comments
 (0)