'How to prevent Angular Material mat-select change option?
<mat-form-field appearance="fill">
<mat-label>Favorite food</mat-label>
<mat-select [formControl]="topFormControl" [(value)]="topSelectValue">
<mat-option *ngFor="let food of foods" [value]="food" >
{{food.viewValue}}
</mat-option>
</mat-select>
</mat-form-field>
ngOnInit(): void {
this.topFormControl.valueChanges
.pipe(
startWith(this.topFormControl.value),
pairwise()
).subscribe(
([old, cur]) => {
if(
//cur.value === 's'
){
//prevent user select the option, force mat-select still shows the old option.
}
}
);
}
foods: Food[] = [
{ value: 's', viewValue: 'Steak' },
{ value: 'p', viewValue: 'Pizza' },
{ value: 't', viewValue: 'Tacos' },
];
Is there any solution when user select Steak in Favorite food, prevent mat-select to show Steak but keep the old option?
Thanks a lot.
Solution 1:[1]
I corrected some extra properties... such as num.value, e.value, .toString
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Bedrock')
.addItem('Hyperlink Phone', 'menuHyperLinkPhone')
.addToUi();
}
function menuHyperLinkPhone() {
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var activeCell = ss.getActiveCell();
var num = activeCell.getValue().toString();
if (num.length == 0){
ss.toast("Length is 0.")
return;
}
if (num.indexOf("ctrlq.org") !== -1) {
return;
}
if (num.length == 10) {
console.log(num)
console.log(typeof num)
ss.toast("Length is 10.")
activeCell.setValue('=HYPERLINK("https://ctrlq.org/call/'+num+'","'+FormatPhoneNumber(num)+'")');
}
if (num.length > 10) {
ss.toast("Length is greater than 10.")
activeCell.setValue('=HYPERLINK("https://ctrlq.org/call/'+num.substring(0,10)+'","'+FormatPhoneNumber(num)+'")');
}
}
function FormatPhoneNumber(number) {
var num = number;
var length = num.length;
if(length == 0){
return num;
}
if(length == 10){
var areacode = num.substring(0,3)
var prefix = num.substring(3,6)
var lastfour = num.substring(6,10)
num = "("+areacode+") "+prefix+"-"+lastfour;
return num;
}
if(length > 10){
var areacode = num.substring(0,3)
var prefix = num.substring(3,6)
var lastfour = num.substring(6,10)
var extension = num.substring(10)
num = "("+areacode+") "+prefix+"-"+lastfour+" ("+extension+")";
return num;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Salomon |
