mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Add validation to the numpad (#387)
This works the same way as upstream - if you close the editor with an invalid (red-highlighted) input, the editor reverts to the original input.
This commit is contained in:
parent
8dfb3d8141
commit
c36a615f07
1 changed files with 4 additions and 2 deletions
|
@ -225,11 +225,12 @@ Blockly.FieldNumber.numPadButtonTouch_ = function() {
|
|||
// Splice in the new value
|
||||
var newValue = oldValue.slice(0, selectionStart) + spliceValue + oldValue.slice(selectionEnd);
|
||||
// Updates the display. The actual setValue occurs when the field is stopped editing.
|
||||
Blockly.FieldTextInput.htmlInput_.value = Blockly.FieldTextInput.htmlInput_.defaultValue = newValue;
|
||||
Blockly.FieldTextInput.htmlInput_.value = newValue;
|
||||
// Resize and scroll the text field appropriately
|
||||
Blockly.FieldNumber.superClass_.resizeEditor_.call(Blockly.FieldNumber.activeField_);
|
||||
Blockly.FieldTextInput.htmlInput_.setSelectionRange(newValue.length, newValue.length);
|
||||
Blockly.FieldTextInput.htmlInput_.scrollLeft = Blockly.FieldTextInput.htmlInput_.scrollWidth;
|
||||
Blockly.FieldNumber.activeField_.validate_();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -249,11 +250,12 @@ Blockly.FieldNumber.numPadEraseButtonTouch_ = function() {
|
|||
newValue = oldValue.slice(0, selectionStart - 1) + oldValue.slice(selectionStart);
|
||||
}
|
||||
// Update the display to show erased value.
|
||||
Blockly.FieldTextInput.htmlInput_.value = Blockly.FieldTextInput.htmlInput_.defaultValue = newValue;
|
||||
Blockly.FieldTextInput.htmlInput_.value = newValue;
|
||||
// Resize and scroll the text field appropriately
|
||||
Blockly.FieldNumber.superClass_.resizeEditor_.call(Blockly.FieldNumber.activeField_);
|
||||
Blockly.FieldTextInput.htmlInput_.setSelectionRange(newValue.length, newValue.length);
|
||||
Blockly.FieldTextInput.htmlInput_.scrollLeft = Blockly.FieldTextInput.htmlInput_.scrollWidth;
|
||||
Blockly.FieldNumber.activeField_.validate_();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue