Skip to content

Commit

Permalink
Move logic for new value all into single function rather than two
Browse files Browse the repository at this point in the history
  • Loading branch information
nstrayer committed Nov 6, 2023
1 parent 310b145 commit 0170372
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions inst/editor/src/SettingsPanel/SettingsInput/IdInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export function IdInput({

const bindingIds = getAllInputOutputIdsInApp(ui_tree);

const updateValue = (newValue: string) => {
const handleNewValue = (e: React.ChangeEvent<HTMLInputElement>) => {
// Replace spaces with underscores
newValue = newValue.replace(/ /g, "_");
const newValue = e.target.value.replace(/ /g, "_");

// Check if the requested new value is already in use and set invalid if it is
const isTakenId = bindingIds.includes(newValue) && newValue !== value;
Expand Down Expand Up @@ -121,9 +121,7 @@ export function IdInput({
// the way to an empty field getting stuck writing out an id that
// contains another id as a prefix
value={isInvalid ? tempValue : value}
onChange={(e) => {
updateValue(e.target.value);
}}
onChange={handleNewValue}
type="text"
/>
{boundToServer && (
Expand Down

0 comments on commit 0170372

Please sign in to comment.