Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sweet alert 2 multiple checkbox

I'm using this "sweet alert 2", I I need of multiple checkbox, In documentation there is 'input-radio' option with multiple choice, but only single choice for checkbox option.

Is there possibily to use this script with checkbox multiple choice?

swal({
  title: 'Select color',
  input: 'radio',
  inputOptions: {
    '#ff0000': 'Red',
    '#00ff00': 'Green',
    '#0000ff': 'Blue'
  }
})

thanks

like image 408
cloude Avatar asked Nov 30 '25 04:11

cloude


1 Answers

It is not supported per se, but you can easily achieve that by writing your own HTML:

swal({
    title: 'Multiple checkbox inputs',
    html: `
            <div class="form-check">
                <input class="form-check-input" type="checkbox" value="" id="checkbox1">
                <label class="form-check-label" for="checkbox1">
                    checkbox1
                </label>
            </div>
            <div class="form-check">
                <input class="form-check-input" type="checkbox" value="" id="checkbox2">
                <label class="form-check-label" for="checkbox2">
                    checkbox2
                </label>
            </div>
    `,
    focusConfirm: false,
    preConfirm: () => {
        console.log('Is checkbox1 checked:' + document.getElementById('checkbox1').checked);
        console.log('Is checkbox2 checked:' + document.getElementById('checkbox2').checked);
    }
});
like image 73
I.Arinov Avatar answered Dec 02 '25 16:12

I.Arinov