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

137
Visualizações
Validate form selection option custom input base on product type EDIT

So I think my last question wasn't cleared. Currently I am doing form validation for my project. I have form input with main field of "sku", "name", and "price", with custom select options of product type which have three products(Book, dvd, furniture) each product type has an input area base on the product selected, for example:

[enter image description here][1]

I am able to validate name, price, sku, and select option for errors. I can also console.log product type base on the value selected. The only problem is, I can't stop the form to submit even if my select option have empty input field. I can validate the error of that field only when user type something that is not of corrected value but if user select the option and the field is blank, submit field still able to submit. How would I write a condition that stop submission when the selected input form is blank? Example: "If productType is book, and that book value weight is empty, throw error: weight is needed, else submit.

function for handle submission: This field validate if there's an error, main form is empty, and if option not selected.

 const handleSubmit = (event) => {
event.preventDefault();

if (
  Object.keys(errors).length === 0 &&
  Object.keys(formValues).length !== 0 &&
  select !== ""
)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

try placing the 'required' straight after the "<select required"

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