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

Prompt fire reject if okey pressed with empty value #2

Open
mnill opened this issue Mar 12, 2020 · 1 comment
Open

Prompt fire reject if okey pressed with empty value #2

mnill opened this issue Mar 12, 2020 · 1 comment

Comments

@mnill
Copy link

mnill commented Mar 12, 2020

if (r.value) {

must be if ('value' in r) {

@mnill mnill changed the title Prompt rejection if okey pressed with empty value Prompt fire reject if okey pressed with empty value Mar 12, 2020
@kirschkern
Copy link

I'm editing existing values using $prompt and want to support empty values as well. Due to the current implementation, I get an error when the user wants to remove the existing value.
In this case I cannot distinguish between an error or just an empty value.

To workaround this, l I've copied the $prompt method and added a modified version to my project.

This is the code I use:

import Vue from "vue";
import VueSimpleAlert from "vue-simple-alert";
import Swal from "sweetalert2";

Vue.prototype.$prompt = function (message, defaultText, title, type, options) {
    return new Promise(function (resolve, reject) {
        var mixedOptions = Object.assign(Object.assign({}, VueSimpleAlert.globalOptions), options);
        mixedOptions.title = title || mixedOptions.title;
        mixedOptions.inputValue = defaultText;
        mixedOptions.html = message || mixedOptions.text;
        mixedOptions.type = type || mixedOptions.type;
        mixedOptions.showCancelButton = true;
        mixedOptions.input = mixedOptions.input || "text";

        Swal.fire(mixedOptions)
            .then(function (r) {
                resolve(r.value);
            })
            .catch(function (e) {
                console.log("Error $trompt", e);
                return reject();
            });
    });
};

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