DomingoSL
Estoy usando una versión personalizada de alerta dulce para pedirle a mi usuario un input
. He logrado que todo funcione pero hay un comportamiento extraño, para poder ingresar un texto en el cuadro de entrada tienes que hacer clic en la pantalla primero:
swal({
title: "Aggiornamento profilo",
text: '<br /><form method="post" id="taxcode-update" name="taxcodeUpdate"><input id="admin-tax-code" minlength="3" class="form-control wedding-input-text wizard-input-pad" type="text" name="taxCode" placeholder="Codice fiscale"></form>',
type: "warning",
showCancelButton: false,
confirmButtonText: "Aggiorna il mio profilo",
closeOnConfirm: false
}, function () {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
Ejemplo de trabajo: https://jsfiddle.net/fvkppx06/
jai chauhan
swal({
title: "An input!",
text: "Write something interesting:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top",
inputPlaceholder: "Write something"
},
function(inputValue){
if (inputValue === null) return false;
if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
swal("Nice!", "You wrote: " + inputValue, "success");
});
-
Porque está utilizando una versión anterior de Sweet Alert. Estaba teniendo lo mismo y lo resolví actualizando la biblioteca de alertas dulces desde aquí. lipis.github.io/bootstrap-dulcealert
– Mukesh Salaria
5 de noviembre de 2018 a las 9:59
Usar dulcealerta2. Hay numerosos ejemplos de indicaciones de entrada que se pueden encontrar aquí, todos ellos usando construcciones async/await modernas. Si lo quieres a la antigua, prueba esto:
Swal.fire({
title: "An input!",
text: "Write something interesting:",
input: 'text',
showCancelButton: true
}).then((result) => {
if (result.value) {
console.log("Result: " + result.value);
}
});
Dar el input
el autofocus
etiqueta.
text: '<br /><form method="post" id="taxcode-update" name="taxcodeUpdate">'
+ '<input id="admin-tax-code" autofocus minlength="3" class="form-control wedding-input-text wizard-input-pad" type="text" name="taxCode" placeholder="Codice fiscale">'
+ '</form>',
-
Esta solución funcionará solo la primera vez que llame al modal, eche un vistazo a esta modificación que hice para demostrar que jsfiddle.net/fvkppx06/2 ¿algunas ideas?
– Domingo SL
28 de abril de 2015 a las 13:34
-
no se, lo siento! Aunque la última versión de dulce alerta permite un
type:input
, ¿cuál puede funcionar mejor? @DomingoSL– Albzi
28 de abril de 2015 a las 13:53
La variable utilizada es ‘nombre’
const {value: name} = await swal({
title: 'Input your name',
input: 'text',
inputPlaceholder: 'Enter here'
})
if (name) {
swal('Entered name: ' + name)
}
narsis fe
Solo prueba esto
swal.withForm({
title: 'Cool example',
text: 'Any text that you consider useful for the form',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Get form data!',
closeOnConfirm: true,
formFields: [
{ id: 'name', placeholder:'Name Field' },
{ id: 'nickname', placeholder:'Add a cool nickname' }
], function(isConfirm) {
// do whatever you want with the form data
console.log(this.swalForm); // { name: 'user name', nickname: 'what the user sends' }
})
Mohammad Reza Shahrestani
Utilizar esta :
Swal.fire({
title: "An input!",
text: "Write something interesting:",
input: 'text',
showCancelButton: true ,
confirmButtonColor: 'green'
}).then((result) => {
if (result.value) {
Swal.fire('Result:'+result.value);
}});
SweetAlert tiene un div con tabIndex=”-1″ este fue mi problema, así que si va a inspeccionar y muestra tabIndex=”-1″ dentro de “first div” (debería estar allí), puede obtener HTMLELEMENT usando la siguiente línea:
let div = document.getElementsByClassName("fade modal-lg modal show");
Luego verifique si hay contenido:
console.log(div, "div");
Una vez que llegue allí, esto es lo que funciona para mí:
for (let i = 0; i < div.length; i++) {
console.log(div[i], "div");
console.log(div[i].setAttribute("tabIndex", ""), "div");
}
const tabIndex = () => {
let div = document.getElementsByClassName("fade modal-lg modal show");
console.log(div, "div");
for (let i = 0; i < div.length; i++) {
console.log(div[i].setAttribute("tabIndex", ""), "div");
}
}
const addOption = () => {
tabIndex() //Call my function where I have my tabIndex (div value)
Swal.fire({
title: 'title',
//html: `<input type="text" id="login" class="swal2-input" placeholder="Username" tabIndex="">`,
input: 'text',
inputValue: inputAdd,
inputAttributes: {
autocapitalize: 'off'
},
showCancelButton: true,
confirmButtonText: 'Save',
})
Espero que esto pueda ayudar 😀 (Estuve 4 horas buscando esto)