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

[Dropdown] Add Nullable Option for Single Selection #2072

Closed
chrisandchris opened this issue Apr 6, 2015 · 58 comments
Closed

[Dropdown] Add Nullable Option for Single Selection #2072

chrisandchris opened this issue Apr 6, 2015 · 58 comments

Comments

@chrisandchris
Copy link

If converting any select to a dropdown, for example

<select name="someselect"
    <option value="1" selected="selected">A</option>
    <option value="2">B</option>
    <option value="3">C</option>
</select>

The select is not required, so an empty selection is valid. We already have a value selected (given by something else). But it is not possible to select an empty value from the generated dropdown.

@jlukic
Copy link
Member

jlukic commented Apr 7, 2015

Hi, please check the readme. Please include a jsfiddle demonstrating your bug and a set of reproducible steps.

@chrisandchris
Copy link
Author

Ok, here's the fiddle:

https://jsfiddle.net/christiank/vf7r42ku/

As you see, the first select is ok: No empty value provided in select, no empty value found in dropdown.
In my opinion, the second select must also show an empty selection available, due to given in the origin select element. Same applies to third select, if you do a wrong selection, i think you must be able to select an empty option.

@jlukic
Copy link
Member

jlukic commented Apr 8, 2015

Empty values are used to pass in placeholder text (i.e. "Select Text.."), a few people have complained about this being idiosyncratic.

I need to evaluate whether it makes sense to change this functionality in 2.0 as it will cause breaking changes for anyone who is using it this way in 1.x

@chrisandchris
Copy link
Author

Well, I think we should consider keeping as most backward compatibility as possible, so in my opinion, I would prefer one of the following options:

  • Adding a new class to the select make it nullable or something like that
  • Extending the behavior to just not required select fields (I don't care about undo selection in a required select)

Just created a fiddle to show how this could work with some magic aka. automatization:

https://jsfiddle.net/christiank/khy2z55x/

Some things i fall into was that most options I tried break responsibility. However, I'm not the best JS/HTML-Guru, more type of a PHP-Guru.

@jlukic
Copy link
Member

jlukic commented Apr 8, 2015

I think adding a placeholder setting, that when passed false will not process blank val will allow for both syntax, and also specifying placeholder programmatically.

@jlukic
Copy link
Member

jlukic commented Apr 8, 2015

Added in 2.0.0. Defaults to auto, which will convert values. If a string is specified, will use that string as placeholder, when set to false will ignore any blank values..9b7ecef

jlukic added a commit that referenced this issue Apr 8, 2015
@jlukic
Copy link
Member

jlukic commented Apr 8, 2015

http://jsfiddle.net/8ha5Ltve/ Fiddle with 2

@chrisandchris
Copy link
Author

However, I think this does not solve the problem: how do you undo the selection in a NOT required select? This is the business case I stept into and it seems that your fiddle does not solve this problem. Even if the select is providind an empty option.

@zelenin
Copy link

zelenin commented Apr 12, 2015

#1820

@chrisandchris
Copy link
Author

I totally agree with @zelenin , using an option without a value attribute is quite a dirty solution. Including regarding to form generators in Symfony2 and ZF2. For me, it is not a solution to modify form generator templates just to make it possible to undo selection.

Including backward compatibility, I propose the following solution:

  • Options with empty value attribute are treated the same way
  • If you add an clearable to the select/dropdown class attribute you get the following:
    • Option with empty value is treated as empty option, so used as placeholder and empty value
    • It might also be an option to add an additional X button right to the select to make it easier undoing the selection

@jlukic
Copy link
Member

jlukic commented Apr 13, 2015

I'll circle around this week.

@canyildiz
Copy link

I also agree with @chrisandchris and @zelenin. It's really hard to work with a select box which has less features than a native one. It's being a big issue both on undoing the selection and also on the edit pages to update a record having a value already selected.

@jlukic
Copy link
Member

jlukic commented Apr 20, 2015

There's docs on both clearing dropdowns and restoring to page load defaults. Can you elaborate on what's missing @canyildiz?

@canyildiz
Copy link

@jlukic thank you for preparing those detailed docs. I really appreciate this. But I don't think putting a "Clear" button near the select box is same as selecting the first empty option of select. Second is the common behavior all web users are used to.

@zelenin
Copy link

zelenin commented Apr 21, 2015

@jlukic clear button is a workaround for hack that you are using for placeholder. Dropdown must be maximally repeating native select behavior. Only then it may be more featureous without risk for native features.

@startswithaj
Copy link

Im in the same boat as @chrisandchris

<select name="someselect"
    <option value="" selected="selected">None</option>
    <option value="2">A</option>
    <option value="3">B</option>
</select>

Where the user can select A and then change their mind and re-select None.

Having a reset button is not a solution.

A nullable option that can be passed to .dropdown() would be a great backwards compatible option.

Forcing value="" empty string options to disappear after a user selects is not inline with how the native select works.

@jlukic
Copy link
Member

jlukic commented Apr 30, 2015

I like the idea of nullable, since, to me, both cases make sense. This is the last thing on my checklist for dropdown before putting it down.

@jlukic jlukic changed the title select dropdown empty value if not required [Dropdown] Add Nullable Option for Single Selection May 11, 2015
@startswithaj
Copy link

Any timeframe on this?

Do you want me to have a go at implementing it and doing a PR?

@jlukic jlukic added this to the 2.x Changes milestone Jun 1, 2015
@DarkSide666
Copy link

Wow - more than 2 years have passed and there is still no official way how to do this???
I can't believe my eyes :(

@DarkSide666
Copy link

DarkSide666 commented Aug 21, 2017

Slightly improved version of @ashkonBG script https://jsfiddle.net/hghkwkgv/1/

Also consider to use if(value!="") instead of if(value) to allow 0 as legit select option.

Only bad thing about this solution is that onChange event is not fired when you initialize that field, so you can't clear/reset default selected value which is set on page loading.

Edit:
This version also contains workaround to call onChange on initialization https://jsfiddle.net/hghkwkgv/6/ and few other fixes.

@greatbody
Copy link

@DarkSide666 I believe that we can fork and start a new branch since officer is dead~_~

@DarkSide666
Copy link

DarkSide666 commented Oct 11, 2017

@greatbody Well, yes it looks that @jlukic have no activity for more than 1 month and previously he's not that active too this year. Sad to see that such good repo like Semantic-UI is going down this way. 142 open pull requests, 1070 open issues :(

@akotulu
Copy link

akotulu commented Oct 11, 2017

Sad to see yes, everyone thinks open source is cool and free, maybe use donation button more often.

@DarkSide666
Copy link

I already contribute in multiple open-source projects. That's my 2-cents to open-source community :)

@ashkonBG
Copy link

Contribution is important to open-source projects and all, but what I think others are trying to say is that new features are being added to the project; but this very major, yet so simple, issue still exists that shouldn't have been there since the early version.

@DarkSide666
Copy link

@ashkonBG I completely agree with you

@romaninsh
Copy link

romaninsh commented Oct 18, 2017

I've been a lead on an open-source project for over 10 years. You are not getting any money off it. Donations or ads won't help. The goal is to have multiple secondary officers who would be able to take over, approve PRs and move project ahead should something happen with the lead.

In a current situation, we've invested a tons of work into https://github.com/atk4/ui to use Semantic UI over any other CSS framework. I still think it's a right choice and if we have to support this project somehow, we would be happy to help. But being open-source guys ourselves, we can't put any funds in.

@chrisandchris
Copy link
Author

I really like the syntax of semantic-ui because it's highly readable and much more easier to write as other frameworks, like bootstrap.

But, even with that in mind, it is quite impossible imho to succeed for semantic-ui when the founder does not give any permission/possibility for other people to manage work for him. There is a huge bunch of pull requests open and quite a lot of issues. Forking isn't an option, because a fork will just sink in the dump of forks...

So as long as @jlukic does not respond, it's just as it is. I myself would be able to spend some hours a week to manage issues and pull requests, and I would like to do that for such a good piece of software.

@romaninsh
Copy link

check in to gitter.im / semantic-ui there are some other people who are willing to help.

@chrisandchris
Copy link
Author

@romaninsh But in the end it depends on the founder (@jlukic) to respond, so that he can grant someone access to maintain the repository/project/website.

@ngolforoushan
Copy link

I found adding a new row to database {id:-1, value: null} is the easiest way to deal with this issue.

@ghost
Copy link

ghost commented Jan 23, 2018

Here is a patch that you can use to add a new option to $fn.dropdown();

https://github.com/BisManOnline/Semantic-UI-dropdown-selectPlaceholder

This patch will allow you to set:

allowPlaceholderSelect : true;

@stale
Copy link

stale bot commented Apr 23, 2018

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

@stale stale bot added the stale label Apr 23, 2018
@DarkSide666
Copy link

bump

@stale stale bot removed the stale label Apr 24, 2018
@atahrijouti
Copy link

Yet another Bump

@pbarney
Copy link

pbarney commented Jul 12, 2018

Here's a workaround: If you add something like <option value="0"></option> to the beginning of your dropdown options then you'll get an empty option.

Just make sure your form processing function realizes that a zero value is a non-choice/null.

@greatbody
Copy link

Got Yet another Bump

@prudho
Copy link

prudho commented Sep 3, 2018

You might want to take a look at this: https://fomantic-ui.com/modules/dropdown.html#clearable-selection

@jlukic
Copy link
Member

jlukic commented Sep 10, 2018

I've added a clearable dropdown for next release of SUI in 33d08ec and the proceeding commits.

Pass in clearable: true with any dropdown type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests