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

View File

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

View File

@ -249,7 +249,15 @@ function SelectMapModal({
selectedMapId &&
(!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);
setMapSettingChanges({});

View File

@ -112,7 +112,13 @@ function SelectTokensModal({ isOpen, onRequestClose }) {
async function applyTokenChanges() {
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({});
}
}