Prevent setting a number value to NaN. Select the field value on entry to an input field. State the contents of the input field when describing the field.

This commit is contained in:
Sean Lip
2016-09-19 16:59:24 -07:00
parent 284f71c46a
commit f4e316e8a9
2 changed files with 8 additions and 3 deletions

View File

@@ -30,12 +30,12 @@ blocklyApp.FieldComponent = ng.core
template: `
<input *ngIf="isTextInput()" [id]="mainFieldId" type="text" [disabled]="disabled"
[ngModel]="field.getValue()" (ngModelChange)="field.setValue($event)"
[attr.aria-label]="disabled ? 'Disabled text field' : 'Press Enter to edit text'"
[attr.aria-label]="disabled ? 'Disabled text field' : 'Press Enter to edit text: ' + field.getValue()"
tabindex="-1">
<input *ngIf="isNumberInput()" [id]="mainFieldId" type="number" [disabled]="disabled"
[ngModel]="field.getValue()" (ngModelChange)="field.setValue($event)"
[attr.aria-label]="disabled ? 'Disabled number field' : 'Press Enter to edit number'"
[ngModel]="field.getValue()" (ngModelChange)="setNumberValue($event)"
[attr.aria-label]="disabled ? 'Disabled number field' : 'Press Enter to edit number: ' + field.getValue()"
tabindex="-1">
<div *ngIf="isDropdown()">
@@ -78,6 +78,10 @@ blocklyApp.FieldComponent = ng.core
// this.generateElementNames() are unique.
this.idMap = this.utilsService.generateIds(elementsNeedingIds);
},
setNumberValue: function(newValue) {
// Do not permit a residual value of NaN after a backspace event.
this.field.setValue(newValue || 0);
},
generateAriaLabelledByAttr: function(mainLabel, secondLabel) {
return mainLabel + ' ' + secondLabel;
},

View File

@@ -454,6 +454,7 @@ blocklyApp.TreeService = ng.core
break;
} else if (currentNode.tagName == 'INPUT') {
currentNode.focus();
currentNode.select();
this.notificationsService.setStatusMessage(
'Type a value, then press Escape to exit');
break;