question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Options with empty value will not be shown

See original GitHub issue
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css" rel="stylesheet"/>
  <script src="https://code.jquery.com/jquery-3.4.0.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js"></script>  

</head>
<body>

  
<select name="SSS" id="SSS">
<option value="">&nbsp;</option>
<option value="1">S0</option>
<option selected="selected" value="2">S1</option>
<option value="3">S2</option>
</select>

<script>
  $(document).ready(function () {
    $("#SSS").select2({
      placeholder: "",
      width: "resolve"
    });
  });
</script>
  
</body>
</html>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
morganarnelcommented, Feb 8, 2022

An empty placeholder option is unlikely to contain a value=“” attribute, whereas null options will include this. It’s not hard to distinguish between the two.

I think this should be looked into again, as the current implementation requires someone to write more code to initialise select2 on elements that should show these options.

0reactions
stale[bot]commented, Mar 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

show empty value in html select element - Stack Overflow
I want to let the user know that the value I got from the server is not a valid option. What I'd like...
Read more >
Handling Null and Other Special Values - Tableau Help
Show Data at Default Position - show the data at a default location on the axis. The null values will still be included...
Read more >
Should a blank option always be included in <select> inputs?
It just seems slightly strange to change the options of required <select> fields based on whether the value has previously been set. This...
Read more >
Blank, Coalesce, IsBlank, and IsEmpty functions in Power Apps
Some controls and data sources use an empty string to indicate a "no value" condition. To simplify app creation, the IsBlank and Coalesce ......
Read more >
Changing the display of null values - MicroStrategy
Clear the Use default check box under Null display settings. · If desired, enter the value to be displayed when an empty value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found