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

201
Visualizações
Can't pass proper value in form, react

I have created a form in react using Formiz. But it's not sending right value.

Here is a working CodeSandbox: https://codesandbox.io/s/formiz-pricing-wizard-forked-fcnsn?file=/src/fields/fieldradio.js

Currently it is sending me this value:

wrong value

But it should send me this value:

right value

I already tried changing step1.js from this:

const transformOptions = (options) =>
  options.map(({ subCategory, price, radioImage }, i) => ({
    label: <span>{subCategory}</span>,
    id: `${subCategory}-${i}`,
    value: `${price}`,
    image: radioImage
  }));

To this:

const transformOptions = (options) =>
  options.map(({ subCategory, price, radioImage }, i) => ({
    label: <span>{subCategory}</span>,
    id: `${subCategory}-${i}`,
    value: `${subCategory} - ${price}`,
    image: radioImage
  }));

It sends me the right values but totalPrice function in MyForm.js stops working:

const totalPrice = React.useMemo(() => {
    return categories.reduce(
      (total, c) =>
        total + (myForm.values[c] ? parseInt(myForm.values[c], 10) : 0),
      0
    );
  }, [myForm.values]);

Will anyone please help me to fix it? Because I've been trying to find a solution for hours but still couldn't find one and can't wrap my head around what's going wrong!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Since you modified value from ${price} to ${subCategory} - ${price} now your totalPrice is broken because in myForm.values[c] there is no more just the price but the subCategory also.

To solve this it's just necessary fix your totalPrice in this way:

  const totalPrice = React.useMemo(() => {

    return categories.reduce(
      (total, c) =>
        total +
        (myForm.values[c]?.split("-")[1]
          ? parseInt(myForm.values[c]?.split("-")[1], 10)
          : 0),
      0
    );
  }, [myForm.values]);

I replaced myForm.values[c] with myForm.values[c]?.split("-")[1] in order to "clean" value from subCategory part and leave just price.

Here your codesandbox modified.

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