• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

127
Vistas
Enable button focus only if variable value changed

I want to enable the below button name completeSubmissionButton only when value of variable isSaving changed from "inProgress" to "Saved". I'm not sure how to do it? As per below condition, focus of the button is enabled when form status is in progress and form is valid but I want to enable only when form is valid and form status changes from inprogress to saved and focus should be enable once. Problem, I have is when form is editable (meaning in progress), it always moves the focus to complete button and I'm not able to edit the current text button

  console.log("isSaving", isSaving); //values are isProgress or Saved or idle
  console.log("isFormValid", isFormValid); // true or false
 
  useEffect(() => {
    if( completeSubmissionButton?.current && isSaving === SAVING_STATUS.IN_PROGRESS && isFormValid){
      completeSubmissionButton.current.focus();
    }
    
  });
almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Right now, your condition checks if isSaving === SAVING_STATUS.IN_PROGRESS.

You want to check instead for if isSaving === SAVING_STATUS.SAVED and another condition to let you know if it just changed from in progress to saved.

You can have another variable to notate what the previous status was. So you can check for isSaving === SAVING_STATUS.SAVED && isSavingPrev === SAVING_STATUS.IN_PROGRESS.

Alternatively, you could create a condition just for the focus() thing such as

if(wheneverYourIsSavingGoesFromProgressToSaved) {
  isSaving = SAVING_STATUS.SAVED;
  focusButton = true;
}

...

useEffect(() => {
  if(completeSubmissionButton?.current && focusButton && isFormValid){
    completeSubmissionButton.current.focus();
    focusButton = false;
  }
}) 
almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda