I am working on a project in which I open a list of "characters", from there I have an action button to save the data of the character, but before saving, I want to open an alert in which a drop-down list with a couple of options, which will also be saved together with the other data. My problem is that I can't execute the dropdown list code I pull from https://sweetalert2.github.io/ ,
const { value: fruit } = await Swal.fire({
title: 'Select field validation',
input: 'select',
inputOptions: {
'Fruits': {
apples: 'Apples',
bananas: 'Bananas',
grapes: 'Grapes',
oranges: 'Oranges'
},
'Vegetables': {
potato: 'Potato',
broccoli: 'Broccoli',
carrot: 'Carrot'
},
'icecream': 'Ice cream'
},
inputPlaceholder: 'Select a fruit',
showCancelButton: true,
inputValidator: (value) => {
return new Promise((resolve) => {
if (value === 'oranges') {
resolve()
} else {
resolve('You need to select oranges :)')
}
})
}
})
if (fruit) {
Swal.fire(`You selected: ${fruit}`)
}
I want to use adapt a similar dropdown list in the following script.
<script>
function confirmar(id_matricula) {
swal({
title: "Confirmación",
text: "¿Agregar este personaje al listado?",
type: "warning",
showCancelButton: true,
confirmButtonClass: "btn-danger",
confirmButtonText: "Confirmar",
closeOnConfirm: false,
cancelButtonText: "Cancelar"
},
function () {
$('#tabla_listado_gral_personas').html('<p style="text-align:center;"><img src="<?php echo base_url(); ?>./images/reload2.gif" /></p>');
$.ajax({
url: base_url + "DatosPersona/confirmar",
type: "GET",
data: {
id_matricula: id_matricula
}
}).done(function (data) {
$('#tabla_personajes_listar').load(base_url + "DatosPersona/cargar_tabla_personajes/", function () {
$(this).html();
});
//
swal("Confirmado!", "Se guardó en el listado", "success");
});
});
}
I have the plugin installed in 'project\js\plugins\sweetalert.min.js' , I don't know if I have to add something else, change it to 'project\js\plugins\sweetalert2.min.js' but it doesn't work either, I don't know It really has to be done, I'm still learning.
In the end I only stayed with the sweetalert, I could not configure the sweetalert2. I have everything based on the first. Cheers