FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(forms): default to unsetValue for value accessors by sis0k0 · Pull Request #846 · NativeScript/nativescript-angular · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (7) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or 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
@@ -1,5 +1,7 @@
import { ControlValueAccessor } from "@angular/forms";
import { View } from "tns-core-modules/ui/core/view";
import { View, unsetValue } from "tns-core-modules/ui/core/view";

import { isBlank } from "../../lang-facade";

export class BaseValueAccessor<TView extends View> implements ControlValueAccessor {
private pendingChangeNotification: any = 0;
Expand Down Expand Up @@ -28,5 +30,9 @@ export class BaseValueAccessor<TView extends View> implements ControlValueAccess
this.view.isEnabled = !isDisabled;
}

writeValue(_: any) { }
writeValue(_: any) {}

protected normalizeValue(value: any): any {
return isBlank(value) ? unsetValue : value;
}
}
This file contains hidden or 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
Expand Up @@ -34,6 +34,7 @@ export class CheckedValueAccessor extends BaseValueAccessor<Switch> { // tslint:
}

writeValue(value: any): void {
this.view.checked = value;
const normalized = super.normalizeValue(value);
this.view.checked = normalized;
}
}
This file contains hidden or 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
Expand Up @@ -34,6 +34,7 @@ export class DateValueAccessor extends BaseValueAccessor<DatePicker> { // tslint
}

writeValue(value: any): void {
this.view.date = value;
const normalized = super.normalizeValue(value);
this.view.date = normalized;
}
}
This file contains hidden or 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
Expand Up @@ -33,6 +33,7 @@ export class NumberValueAccessor extends BaseValueAccessor<Slider> { // tslint:d
}

writeValue(value: any): void {
this.view.value = value;
const normalized = super.normalizeValue(value);
this.view.value = normalized;
}
}
This file contains hidden or 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
Expand Up @@ -50,7 +50,8 @@ export class SelectedIndexValueAccessor extends BaseValueAccessor<SelectableView
private viewInitialized: boolean;

writeValue(value: any): void {
this.value = value;
const normalized = super.normalizeValue(value);
this.value = normalized;

if (this.viewInitialized) {
this.view.selectedIndex = this.value;
Expand Down
This file contains hidden or 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
Expand Up @@ -48,6 +48,7 @@ export class TextValueAccessor extends BaseValueAccessor<TextView> { // tslint:d
}

writeValue(value: any): void {
this.view.text = value;
const normalized = super.normalizeValue(value);
this.view.text = normalized;
}
}
This file contains hidden or 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
Expand Up @@ -36,6 +36,7 @@ export class TimeValueAccessor extends BaseValueAccessor<TimePicker> { // tslint
}

writeValue(value: any): void {
this.view.time = value;
const normalized = super.normalizeValue(value);
this.view.time = normalized;
}
}

Back | FazBrowse Home | New Git URL