Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read only fields #5

Merged
merged 5 commits into from
Mar 2, 2018
Merged

Read only fields #5

merged 5 commits into from
Mar 2, 2018

Conversation

edetec
Copy link
Contributor

@edetec edetec commented Feb 27, 2018

Add read-only behavior, and display '(optional)' label for not required fields

@coveralls
Copy link

coveralls commented Feb 27, 2018

Pull Request Test Coverage Report for Build 77

  • 22 of 25 (88.0%) changed or added relevant lines in 5 files are covered.
  • 7 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-2.8%) to 78.319%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/ng-xform/select-field/select-field.component.ts 1 4 25.0%
Files with Coverage Reduction New Missed Lines %
src/ng-xform/ng-xform.component.ts 7 54.17%
Totals Coverage Status
Change from base Build 76: -2.8%
Covered Lines: 284
Relevant Lines: 336

💛 - Coveralls

<div *ngIf="!editing" id="{{field.key}}-label">
<strong>{{ field.label }}</strong>
<div *ngIf="!isEditing" id="{{field.key}}-label">
<strong>{{ field.label }}</strong> <small *ngIf="isOptional" style="color: gray">(optional)</small>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the 'optional' part be only in the editable div? It will never be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right


get isOptional(): boolean {
return this.editing && !this.field.readOnly &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would avoid testing if it is 'editing' if you remove the 'optional' part from the div in the non-editing state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right

<strong *ngIf="!editing">{{ field.label }}</strong>
<p class="text-muted" *ngIf="!editing">{{ form?.controls[elementId]?.value | valueSuffix: field.unit }}</p>
<div *ngIf="!isEditing" id="{{elementId}}-label">
<strong>{{ field.label }}</strong> <small *ngIf="isOptional" style="color: gray">(optional)</small>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

<div *ngIf="!editing" id="{{field.key}}-label">
<strong>{{ field.label }}</strong>
<div *ngIf="!isEditing" id="{{field.key}}-label">
<strong>{{ field.label }}</strong> <small *ngIf="isOptional" style="color: gray">(optional)</small>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

<div [hidden]="editing" id="{{field.key}}-label">
<strong>{{ field.label }}</strong>
<div [hidden]="isEditing" id="{{field.key}}-label">
<strong>{{ field.label }}</strong> <small *ngIf="isOptional" style="color: gray">(optional)</small>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@@ -44,6 +43,14 @@ export class HomeComponent implements OnInit {
Validators.email
]
}),
new SelectField({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A read-only SelectField doesn't make much sense. But ok, we can review that later

@@ -53,6 +53,10 @@ export class SelectFieldComponent extends BaseDynamicFieldComponent<SelectField>
this.select.registerOnTouched(this._onTouched);
this.viewModel.subscribe((value: any) => {
if (this.field.searchByValueAttributeHandler) {
if (value === undefined || value === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could value be undefined?

Copy link
Contributor Author

@edetec edetec Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If initialize the FormControl with undefined value or call form.setValue with undefined for the key of this control

<div *ngIf="editing" id="{{elementId}}-div" class="form-group" [formGroup]="form" [ngClass]="displayFieldCss()">
<label for="{{elementId}}">{{field.label}}</label>
<div *ngIf="isEditing" id="{{elementId}}-div" class="form-group" [formGroup]="form" [ngClass]="displayFieldCss()">
<label for="{{elementId}}">{{field.label}}</label> <small *ngIf="isOptional" style="color: gray">(optional)</small>
Copy link
Member

@igortg igortg Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DRY!

Optional should be a component named <optional-tag> or something alike.

@edetec edetec merged commit b53545e into master Mar 2, 2018
@edetec edetec deleted the read-only-fields branch April 12, 2018 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants