Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
input field doesnt allow to edit

Hi guys I am trying to edit the input field below and cant. I getting some data from a server and I am putting this data on the value of the input. The idea is that one we click the icon to allow the field to be editable but still cant edit.

This is the input with props customised:


 <input
          {...field}
          //   required={props.required}
          disabled={props.disabled}
          value={props.value}
          type={props.type}
          autoComplete={props.autoComplete}
          pattern={props.pattern}
          className={`mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm  rounded-md ${
            error ? 'border-red-500' : 'border-gray-500'
          }
          ${
            props.disabled
              ? 'disabled:shadow-none disabled:bg-slate-50 disabled:text-slate-500 disabled:border-slate-200'
              : 'border-gray-500'
          } `}
        />

And here is where I am actually using it. So once I click the icon its value comes true but cant edit inside the already value that returns from the server.


const [agent, setAgent] = useState<EstateAgentResponse | null>(null)
  const [enableField, setEnableField] = useState<boolean>(false)

  useEffect(() => {
    const fetchData = async () => {
      try {
        const { id } = params

        const agentUsers = await getEstaAgentUsers(parseInt(id!, 10))
        const agent = await getEstateAgentById(parseInt(id!, 10))

        setAgentUsers(agentUsers)
        setAgent(agent)
      } catch (error) {
        // ToDo:
        // We should handle the error message
        toast.error(`${error}`)
      }
    }
    fetchData()
  }, [])

 const handleInputField = () => {
    setEnableField(!enableField)
  }

<PencilAltIcon className="block h-4 w-4" aria-hidden="true" onClick={handleInputField} />
                              <InputField
                                name="businessName"
                                label="Business name"
                                disabled={!enableField}
                                value={agent?.businessName}
                                type="text"
                                rules={{
                                  required: 'This is required',
                                }}
                              />
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to made the state instead of direct passing the value agent?.businessName in InputField as you can see the below code, I hope this would be helpful and also works. thanks

const [agent, setAgent] = useState<EstateAgentResponse | null>(null)
  const [enableField, setEnableField] = useState<boolean>(false);
  const [businessName, setBusinessName] = useState('');

  useEffect(() => {
    const fetchData = async () => {
      try {
        const { id } = params

        const agentUsers = await getEstaAgentUsers(parseInt(id!, 10))
        const agent = await getEstateAgentById(parseInt(id!, 10));
        setBusinessName(agent?.businessName);

        setAgentUsers(agentUsers)
        setAgent(agent)
      } catch (error) {
        // ToDo:
        // We should handle the error message
        toast.error(`${error}`)
      }
    }
    fetchData()
  }, [])

 const handleInputField = () => {
    setEnableField(!enableField)
  }

<PencilAltIcon className="block h-4 w-4" aria-hidden="true" onClick={handleInputField} />
                              <InputField
                                name="businessName"
                                label="Business name"
                                disabled={!enableField}
                                value={businessName}
                                onChange={e => setBusinessName(e.target.name)}
                                type="text"
                                rules={{
                                  required: 'This is required',
                                }}
                              />

In input component you need to add onChange prop as you can see the below code

<input
          {...field}
          //   required={props.required}
          disabled={props.disabled}
          value={props.value}
          onChange={props.onChange}
          type={props.type}
          autoComplete={props.autoComplete}
          pattern={props.pattern}
          className={`mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm  rounded-md ${
            error ? 'border-red-500' : 'border-gray-500'
          }
          ${
            props.disabled
              ? 'disabled:shadow-none disabled:bg-slate-50 disabled:text-slate-500 disabled:border-slate-200'
              : 'border-gray-500'
          } `}
        />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!