Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda