Changed map and token select number inputs to not prepend a 0 when typing numbers

This commit is contained in:
Mitchell McCaffrey 2020-08-07 13:56:03 +10:00
parent 5dc338471d
commit 239f377aef
4 changed files with 19 additions and 5 deletions

View File

@ -64,7 +64,7 @@ function MapSettings({
<Input <Input
type="number" type="number"
name="gridX" name="gridX"
value={(map && map.gridX) || 0} value={`${(map && map.gridX) || 0}`}
onChange={(e) => onChange={(e) =>
onSettingsChange("gridX", parseInt(e.target.value)) onSettingsChange("gridX", parseInt(e.target.value))
} }
@ -78,7 +78,7 @@ function MapSettings({
<Input <Input
type="number" type="number"
name="gridY" name="gridY"
value={(map && map.gridY) || 0} value={`${(map && map.gridY) || 0}`}
onChange={(e) => onChange={(e) =>
onSettingsChange("gridY", parseInt(e.target.value)) onSettingsChange("gridY", parseInt(e.target.value))
} }

View File

@ -19,7 +19,7 @@ function TokenSettings({
<Input <Input
type="number" type="number"
name="tokenSize" name="tokenSize"
value={(token && token.defaultSize) || 1} value={`${(token && token.defaultSize) || 0}`}
onChange={(e) => onChange={(e) =>
onSettingsChange("defaultSize", parseInt(e.target.value)) onSettingsChange("defaultSize", parseInt(e.target.value))
} }

View File

@ -249,7 +249,15 @@ function SelectMapModal({
selectedMapId && selectedMapId &&
(!isEmpty(mapSettingChanges) || !isEmpty(mapStateSettingChanges)) (!isEmpty(mapSettingChanges) || !isEmpty(mapStateSettingChanges))
) { ) {
await updateMap(selectedMapId, mapSettingChanges); // Ensure grid values are positive
let verifiedChanges = { ...mapSettingChanges };
if ("gridX" in verifiedChanges) {
verifiedChanges.gridX = verifiedChanges.gridX || 1;
}
if ("gridY" in verifiedChanges) {
verifiedChanges.gridY = verifiedChanges.gridY || 1;
}
await updateMap(selectedMapId, verifiedChanges);
await updateMapState(selectedMapId, mapStateSettingChanges); await updateMapState(selectedMapId, mapStateSettingChanges);
setMapSettingChanges({}); setMapSettingChanges({});

View File

@ -112,7 +112,13 @@ function SelectTokensModal({ isOpen, onRequestClose }) {
async function applyTokenChanges() { async function applyTokenChanges() {
if (selectedTokenId && !isEmpty(tokenSettingChanges)) { if (selectedTokenId && !isEmpty(tokenSettingChanges)) {
await updateToken(selectedTokenId, tokenSettingChanges); // Ensure size value is positive
let verifiedChanges = { ...tokenSettingChanges };
if ("defaultSize" in verifiedChanges) {
verifiedChanges.defaultSize = verifiedChanges.defaultSize || 1;
}
await updateToken(selectedTokenId, verifiedChanges);
setTokenSettingChanges({}); setTokenSettingChanges({});
} }
} }