Opened 7 years ago

Closed 4 years ago

#17081 closed defect (patchwelcome)

dijit/form/Select removeOption doesn't clear the select when the last item is removed

Reported by: haddow777 Owned by:
Priority: undecided Milestone: 1.13
Component: Dijit - Form Version: 1.8.3
Keywords: Cc:
Blocked By: Blocking:

Description

I have a situation where I am wanting to remove all the options from a select widget. When I remove the last option, it leaves it in the select, not the dropdown portion but the displayed part beside the dropdown button.

I have removed the option in a number of different ways thinking that maybe I was removing only part of an option, but the most thorough method of removing options I could think of (select.removeOption(select.getOptions())) doesn't remove the text. The only thing I have been able to do to change the value is to add an option. I don't think this is a good way of dealing with the situation though.

I'm not sure if there is another method of clearing the select's display, but it would seem to me that it should be cleared or blanked out if the last option is removed.

Change History (6)

comment:1 Changed 7 years ago by Douglas Hays

You should call set("value", "", true, ""); but this doesn't work since Select's _setValueAttr hasn't been instrumented to understand the formattedValue. In the mean time, just call widget._setDisplay("")

comment:2 Changed 7 years ago by haddow777

First off, thank you for your quick reply. I'm not familiar with the form of set you are describing. I haven't see the extra parameters in the documentation before, could please explain what those extra parameters are doing or point to some documentation that describes what it is supposed to do. Thank you.

Also, I went back and tested more of the removeOption functionality. If I have a list with 2 values, say for example, "One" and "Two" and I remove the "One" option, the select box will display "Two". To me, this implies that the removeOption function will update the display of the select box, and in fact that is the default behaviour I would expect from it. But if I remove both of them at the same time, the display will show "One". To me, that is inconsistent behaviour. Why would I neet to manually set the display when removing all the options when I don't have to when removing only some of them?

Thank you again

comment:3 Changed 7 years ago by Douglas Hays

Most textbox-type form widgets inherit _setValueAttr from _TextBoxMixin which has the extra parameter signatures. removeOption is not doing any value setting. The observed behavior is a result of trying to set an unset value to the 1st option. When no options, then it just leaves the value as it was.

comment:4 Changed 6 years ago by Douglas Hays

Owner: Douglas Hays deleted
Status: newassigned

comment:5 Changed 6 years ago by Douglas Hays

Status: assignedopen

comment:6 Changed 4 years ago by dylan

Milestone: tbd1.12
Resolution: patchwelcome
Status: openclosed

Given that no one has shown interest in creating a patch in the past 2+ years, I'm closing this as patchwelcome.

Note: See TracTickets for help on using tickets.