-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core/forms): show labels for select fields when readonly
approve api changes in core/forms
- Loading branch information
Showing
12 changed files
with
319 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<ng-container *ngIf="control|async as ctrl"> | ||
<ng-container *ngFor="let choice of instance.filteredChoices; let idx = index"> | ||
<ng-container *ngIf="multiple|async; else singleChoice"> | ||
<span *ngIf="ctrl.value && ctrl.value?.indexOf(choice.value) > -1"> | ||
{{choice.label|translate}}{{ctrl.value[ctrl.value.length - 1] !== choice.value ? ', ': ''}} | ||
</span> | ||
</ng-container> | ||
<ng-template #singleChoice> | ||
<span *ngIf="ctrl.value === choice.value">{{choice.label|translate}}</span> | ||
</ng-template> | ||
</ng-container> | ||
</ng-container> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* @license | ||
* Copyright (C) Gnucoop soc. coop. | ||
* | ||
* This file is part of the Advanced JSON forms (ajf). | ||
* | ||
* Advanced JSON forms (ajf) is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* Advanced JSON forms (ajf) is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Advanced JSON forms (ajf). | ||
* If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
Inject, | ||
ViewEncapsulation | ||
} from '@angular/core'; | ||
import {Observable} from 'rxjs'; | ||
import {filter, map} from 'rxjs/operators'; | ||
|
||
import {AjfBaseFieldComponent} from './base-field'; | ||
import {AjfFormRendererService} from './form-renderer'; | ||
import { | ||
AjfFieldWithChoicesInstance | ||
} from './interface/fields-instances/field-with-choices-instance'; | ||
import {AJF_WARNING_ALERT_SERVICE, AjfWarningAlertService} from './warning-alert-service'; | ||
import {AjfFieldType} from './interface/fields/field-type'; | ||
|
||
@Component({ | ||
templateUrl: 'read-only-select-field.html', | ||
styleUrls: ['read-only-select-field.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.None, | ||
}) | ||
export class AjfReadOnlySelectFieldComponent extends | ||
AjfBaseFieldComponent<AjfFieldWithChoicesInstance<String|number>> { | ||
readonly multiple: Observable<boolean>; | ||
|
||
constructor( | ||
cdr: ChangeDetectorRef, service: AjfFormRendererService, | ||
@Inject(AJF_WARNING_ALERT_SERVICE) was: AjfWarningAlertService) { | ||
super(cdr, service, was); | ||
|
||
this.multiple = this.control.pipe( | ||
filter(control => control != null), | ||
map(() => this.instance.node.fieldType === AjfFieldType.MultipleChoice) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* @license | ||
* Copyright (C) Gnucoop soc. coop. | ||
* | ||
* This file is part of the Advanced JSON forms (ajf). | ||
* | ||
* Advanced JSON forms (ajf) is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the License, | ||
* or (at your option) any later version. | ||
* | ||
* Advanced JSON forms (ajf) is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero | ||
* General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Advanced JSON forms (ajf). | ||
* If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {AjfFieldType, AjfFieldWithChoices, AjfFormSerializer, AjfNodeType} from '@ajf/core/forms'; | ||
import {Component} from '@angular/core'; | ||
import {TestBed} from '@angular/core/testing'; | ||
import {By} from '@angular/platform-browser'; | ||
import {NoopAnimationsModule} from '@angular/platform-browser/animations'; | ||
import {TranslateModule} from '@ngx-translate/core'; | ||
|
||
import {AjfFormsModule} from './public-api'; | ||
|
||
describe('AjfFormRenderer', () => { | ||
beforeEach(async () => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
AjfFormsModule, | ||
NoopAnimationsModule, | ||
TranslateModule.forRoot(), | ||
], | ||
declarations: [ | ||
TestComponent, | ||
], | ||
}); | ||
await TestBed.compileComponents(); | ||
}); | ||
|
||
it('read only select value should equals to label', async () => { | ||
const fixture = TestBed.createComponent(TestComponent); | ||
|
||
fixture.detectChanges(); | ||
await fixture.whenStable(); | ||
fixture.detectChanges(); | ||
await fixture.whenStable(); | ||
|
||
let field = fixture.debugElement.query(By.css('.ajf-field-field')).nativeElement; | ||
expect(field.textContent).toEqual('Black Cat'); | ||
}); | ||
}); | ||
|
||
const testForm = { | ||
choicesOrigins: [ | ||
{ | ||
name: 'choices', | ||
label: 'choices', | ||
type: 'fixed', | ||
choices: [ | ||
{value: 'dog', label: 'Dog'}, | ||
{value: 'cat', label: 'Cat'}, | ||
{value: 'blackcat', label: 'Black Cat'}, | ||
], | ||
}, | ||
], | ||
nodes: [{ | ||
id: 1, | ||
parent: 0, | ||
parentNode: 0, | ||
nodeType: AjfNodeType.AjfSlide, | ||
name: 'slide', | ||
label: 'slide', | ||
conditionalBranches: [{condition: 'true'}], | ||
nodes: [{ | ||
id: 2, | ||
parent: 1, | ||
parentNode: 0, | ||
nodeType: AjfNodeType.AjfField, | ||
name: 'field', | ||
label: 'field', | ||
conditionalBranches: [{condition: 'true'}], | ||
fieldType: AjfFieldType.SingleChoice, | ||
choicesOriginRef: 'choices', | ||
validation: {notEmpty: true} as any | ||
} as unknown as AjfFieldWithChoices<string>] | ||
}], | ||
} as any; | ||
|
||
@Component({ | ||
template: '<ajf-form readonly [form]="form"></ajf-form>', | ||
}) | ||
class TestComponent { | ||
form = AjfFormSerializer.fromJson(testForm, {field: 'blackcat'}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.