Error when editing field in local studio, resolved by starting over.

9 replies
Last updated: Mar 23, 2022
hello, i’m trying to follow this tutorial on Creating a custom input component. I make it to this point (https://youtu.be/Sg-H5CKc6Dk?t=686 ) — but whenever I edit the field in my local studio, i get an error I can’t figure out:
Uncaught TypeError: _formBuilder.default is undefined

the error goes back to line 22:
onChange(PatchEvent.from(inputValue ? … )

not sure what i’m doing wrong here i think i’ve copied the example exactly
Mar 17, 2022, 4:29 AM
Jimmy, can you please paste your component's code somewhere and send it here?
Mar 17, 2022, 4:56 AM
Mar 17, 2022, 11:46 AM
& in my `schema.js`:

        {
          title: 'Shape',
          name: 'shape',
          type: 'url',
          inputComponent: ShapeInput
        }
Mar 17, 2022, 11:46 AM
Hey Jimmy, thanks for your question. Out of curiosity maybe try rebuilding the studio after these changes are made and refreshing it in the browser. Also if possible can you re-post your
gist
it seems to be out of date or not working when attempting to visit it to look over your code
Mar 17, 2022, 3:23 PM
import React, { useEffect, useState } from "react";
import PatchEvent, { set, unset } from "@sanity/form-builder";
import { FormField } from "@sanity/base/components";
import { TextInput } from '@sanity/ui';

const ShapeInput = React.forwardRef((props, ref) => {
  const {
    type,
    value,
    readOnly,
    placeholder,
    markers,
    presence,
    compareValue,
    onFocus,
    onBlur,
    onChange
  } = props;

  const handleChange = React.useCallback((event) => {
    const inputValue = event.currentTarget.value
    onChange(PatchEvent.from(inputValue ? set(inputValue) : unset()))
  }, [onChange]);

  return (
    <FormField
      description={type.description} // Creates description from schema
      title={type.title} // Creates label from schema title
      __unstable_markers={markers} // Handles all markers including validation
      __unstable_presence={presence} // Handles presence avatars
      compareValue={compareValue}
    >
      <TextInput 
        value={value}
        readOnly={readOnly}
        placeholder={placeholder}
        onFocus={onFocus}
        onBlur={onBlur}
        onChange={handleChange}
      />
    </FormField>
  );
});

export default ShapeInput;
Mar 17, 2022, 3:26 PM
rebuilt the studio (i.e. ran
sanity start
again); refreshed; still getting the same error
Mar 17, 2022, 3:27 PM
i figured this out! I don’t really know how 🙃 I just started over and it seemed to work
Mar 19, 2022, 3:10 AM
i figured this out! I don’t really know how 🙃 I just started over and it seemed to work
Mar 19, 2022, 3:10 AM
Glad to hear it!
Mar 23, 2022, 9:45 PM

Sanity– build remarkable experiences at scale

The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?