Un foro de discusión para nuestra comunidad de hispano hablante
By janiszapata
#784988
Buenos días:

Quisiera saber cómo puedo deshabilitar el botón "ENVIAR" en caso el usuario no haya adjuntando un archivo (INPUT). Estoy buscando la manera de hacerlo con javascript, si alguien tiene le solución, estaría muy agradecida.

Saludos.
User avatar
By amosbatto
#793747
En las propiedades del campo, puedes marcar la opción Required (Requirido).

Puedes desactivar el botón de submit con este código:
$("#mysubmit").find("button").prop("disabled", true)
Pero no hay una manera facil para reactivarlo porque no hay un change event en campos de file y multipleFile.

Puedes usar JavaScript como este para chequear el número de archivos seleccionados en un multipleFile cuando el formulario es entregado:
Code: Select all
getFormById( $("form").prop("id") ).setOnSubmit( function() {
   if ($("#specFiles").find(".multiplefile-container").length == 0) {
       alert("Por favor seleccione un archivo.");
       return false;
   }
}
User avatar
By milagrosmaria16
#827600
Buenos días,

Estoy intentando deshabilitar el botón "Enviar" y mostrar una alerta siempre y cuando la fecha fin sea menor a la fecha de inicio; estoy utilizando el siguiente código:
Code: Select all
function showOrHideAlertaFecha(date) { 
        var inicio = $('#datFecha').getValue();
  	var fin = $('#datFecha1').getValue();
  
  if ( fin < inicio ) {
    alert("Por favor ingrese las fechas correctas.");
    $("#btnEnviar").find("submit").prop("disabled", true);
    return false;
  } else {
    $("#btnEnviar").find("submit").prop("enabled", true);
    return true;
  }
}
showOrHideAlertaFecha();
$('#btnEnviar').setOnchange(showOrHideAlertaFecha); //execute when checkbox is changed
El botón sigue habilitado y la alerta solo se muestra si pongo esto:
Code: Select all
$('#datFecha1').setOnchange(showOrHideAlertaFecha); //execute when checkbox is changed
Pero esto solo me funcionaría si la fecha fin siempre será seleccionada ultima pero si esto no es así, el código queda sin efecto.

Espero me puedan apoyar por favor, gracias de antemano.
#827602
Utilicé el siguiente código:
Code: Select all
function showOrHideAlertaFecha() { 
    var inicio = $('#datFecha').getValue();
  	var fin = $('#datFecha1').getValue();
  
  if ( fin < inicio ) {
    alert("Por favor ingrese las fechas correctas.");
    return false;
  } else {
    return true;
  }
}
showOrHideAlertaFecha();
getFormById("form-id").setOnSubmit(showOrHideAlertaFecha);
Espero les ayude. :D

The online gambling industry is booming, and with[…]

🚀 Discover the future of crypto trading with Bit e[…]

ucas personal statement help

If you want ucas personal statement help than you […]

Though Many popular NFT Marketplaces are in the cr[…]