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

Input returns empty string if defaultValue not changed #764

Closed
alex-osman opened this issue Nov 8, 2017 · 11 comments · Fixed by #771
Closed

Input returns empty string if defaultValue not changed #764

alex-osman opened this issue Nov 8, 2017 · 11 comments · Fixed by #771

Comments

@alex-osman
Copy link
Contributor

alex-osman commented Nov 8, 2017

A swal with an input element will return an empty string if the original value is unchanged. For example:

swal({
  text: 'Enter some text',
  content: {
    element: 'input',
    attributes: {
      value: 'hello'
    }
  },
buttons: [true, true]
}).then((retVal) => {
  console.log(retVal)
})

The value of retVal is

  • null if you hit cancel
  • "" if you hit okay
  • "somestring" if you actually change the input
  • "" if you remove all the text and submit an empty string

It should be "hello" if you hit okay, not an empty string. There is no way to determine if someone removed all the text and wants to submit an empty string, or if they submitted the defaultValue/value.

I have tried changing value to defaultValue and that has no effect.

I believe this is because the input element is only calling setActionValue on change, and it on init it should be checking if it has a defaultValue, and then calling setActionValue(this.defaultValue)

@t4t5
Copy link
Owner

t4t5 commented Nov 18, 2017

Sounds like a bug, and your analysis seems right. Feel free to send a pull request fixing this if you have time!

@gitspider
Copy link

The issue is still existed in the latest stable version 2.1.2.

@jaspreetsinghchhabra
Copy link

The issue still exists on version 2.1.2.

@GregJArnold
Copy link

This fix was backed out via #774 for some reason.

@jsdev-mario
Copy link

The same error

@joan-teriihoania
Copy link

Same error as well

@nickdavies791
Copy link

Anyone have a solution to this? I still get the same issue.

@DGINXREAL
Copy link

The same error is still exists

@janforth
Copy link

This bug still exists!

@Dennis4720
Copy link

This issue still exists.

@SkyNetRu
Copy link

SkyNetRu commented Mar 17, 2023

This bug still exists!
got around it like this

                swal({
                    title: "Title",
                    text: "Some text",
                    content: {
                        element: "input",
                        attributes: {
                            type: "email",
                            defaultValue: defaultEmail
                        },
                    },
                    button: {
                        text: "Send",
                    }
                }).then(result => {
                    if ( !result ) {
                        result = defaultEmail;
                    }

                    ...
                });

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

Successfully merging a pull request may close this issue.