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 stringIt 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)
Sounds like a bug, and your analysis seems right. Feel free to send a pull request fixing this if you have time!
The issue is still existed in the latest stable version 2.1.2.
The issue still exists on version 2.1.2.
This fix was backed out via #774 for some reason.
The same error
Same error as well
Anyone have a solution to this? I still get the same issue.
Most helpful comment
The issue is still existed in the latest stable version 2.1.2.