Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using with select input #73

Open
vmosoti opened this issue Jan 14, 2018 · 1 comment
Open

Using with select input #73

vmosoti opened this issue Jan 14, 2018 · 1 comment

Comments

@vmosoti
Copy link

vmosoti commented Jan 14, 2018

Anybody with an example on how to use sweet-alert to display a select input?

@mrcool-ru
Copy link

I used this code:

<!-- SweetAlert input select hack-->
<style>
    div.sweet-alert div.form-group input.form-control[placeholder="hidden"] {
        display: none;
    }
</style>
<script>

    swal({
        title: "Alert with select",
        text: '<p">Select something</p>' +
        '<select class="sweet-select">' +
        '   <option value=""></option>' +
        '   <option value="1">one</option>' +
        '   <option value="2">two</option>' +
        '   <option value="3">three</option>' +
        '</select>',
        type: "input",
        html: true,
        inputPlaceholder: 'hidden',
        showCancelButton: true,
        closeOnConfirm: false
    }, function (inputValue) {
        if (inputValue === false) return false;
        if (inputValue === "") {
            swal.showInputError("You need to select something!");
            return false
        }

        swal("It works!", 'Your selected: ' + inputValue, "success");
    });

    //SweetAlert input select hack
    $('body').on('change', '.sweet-select', function () {
        $(this).closest('.sweet-alert')
            .find('div.form-group input.form-control[placeholder="hidden"]')
            .val($(this).val());
    });
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants