t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.39k stars 2.84k forks source link

Content input required to click confirm ? #893

Open geydson opened 5 years ago

geydson commented 5 years ago

swal ({ title: "A chosen product was not the cheapest!", text: "To continue you will need to provide a justification, do you wish to continue? \ n \ nProducts:", icon: "warning", buttons: { cancel: "Cancel", confirm: "Confirm", } content: { element: "input", attributes: { Placeholder: "State the justification ...", type: "text", } } closeOnClickOutside: false, closeOnEsc: false, }) .then ((value) => {

});

How to put content: {element: "input"}, as a required field, when clicking confirm?

michaelCastillo commented 5 years ago

Same here :cry:

usamarauf93 commented 5 years ago

how to resolve ?

dansvel commented 5 years ago

i downt know,,

i tried

content: {
    element: "input",
    attributes: {
    Placeholder: "State the justification ...",
    type: "text",
    required: "required"
}

it got required attribut, but seems not work at all

but the easiest way is

function warn() {
    swal({
        title: "A chosen product was not the cheapest!",
        text: "To continue you will need to provide a justification, do you wish to continue? \ n \ nProducts:",
        icon: "warning",
        buttons: {
            cancel: "Cancel",
            confirm: "Confirm",
        },
        content: {
            element: "input",
            attributes: {
                Placeholder: "State the justification ...",
                type: "text",
                required: "required"
            }
        },
        closeOnClickOutside: false,
        closeOnEsc: false,
    }).then((value) => {
        if (!value) { warn() }
    });
}

warn();

it just repeat the sweet if value is empty,, still looking for other option to resolve,,

KhaledSMIT commented 2 years ago

inputValidator: value => { if (!value) { return "You need to choose something!"; } }