Opened 13 years ago

Closed 12 years ago

#912 closed enhancement (fixed)

[patch][cla] Add ability to set intial values of ComboBox inline

Reported by: aaronmevans@… Owned by: Douglas Hays
Priority: high Milestone: 0.9
Component: Widgets Version: 0.3
Keywords: ComboBox inital values Cc: aaronmevans@…, ktiedt@…
Blocked By: Blocking:

Description

AFAIK, there is no way of initializing a combo box's values when it is created from an inline div tag. This comes up in the situation where I am displaying a form that already has values (eg. I am editing a database row or something).

Example div tag (note the addition of initValue and initSelectValue):

<div name="cb1" dojoType="combobox"

initValue="label1", initSelectValue="value1" style="width: 300px;"></div>

I'm going to attach a patch for ComboBox? with some code to address this. NOTE: my CLA is in the mail (Name: Aaron M Evans, Email: aaronmevans@…).

In this patch, I have added a function called setInitialValues that may be called with an initial value for both the comboBoxValue.value and the comboBoxSelectionValue.value. I added properties called initValue and initSelectValue. At the end of fillInTemplate, I added a call to setInitialValues with these values respectively.

The setInitialValues function checks that both the initValue and initSelectValue are non-null and non-empty. If so, it calls setAllValues with these values and creates a result/option node with the values under the optionsListNode. The result/option node is necessary because without it, if you have forceValidOption set to true and the user moves focus to the combobox text input and then moves focus away (without changing the value), the values will get cleared.

Since I was repeating the same code for creating a result node as in openResultList, I took the liberty of moving the common code to a function called createOptionResultNode.

One final modification: I added code to setAllValues to set the selectedResult according to the passed in values. If they are both empty then I set selectedResult to null. I then removed the setting of selectedResult in selectOption since it will now be taken care of by setAllValues. By having this done in setAllValues, when one attaches functions to the setAllValues method (either before or after), they selectedResult and the values of comboBoxValue and comboBoxSelectedValue are consistent.

I don't see an option for attaching a file, but I'm hoping there will be after I submit the bug...

cheers, aaron

Attachments (5)

ComboBox.js (19.2 KB) - added by aaronmevans@… 13 years ago.
Patch for ComboBox?
ComboBox.patch (3.3 KB) - added by aaronmevans@… 13 years ago.
Patch for ComboBox?
Select.patch (537 bytes) - added by aaronmevans@… 13 years ago.
This Select.patch goes with ComboBox?.patch (patches setAllValues)
ComboBoxValuePatch.diff (1.3 KB) - added by csawyer@… 12 years ago.
Patch file to add value (and defaultValue).
ComboBoxValuePatch.2.diff (1.3 KB) - added by csawyer@… 12 years ago.
[ccla] Patch file to add value (and defaultValue). total workaround

Download all attachments as: .zip

Change History (18)

Changed 13 years ago by aaronmevans@…

Attachment: ComboBox.js added

Patch for ComboBox?

comment:1 Changed 13 years ago by dylan

Milestone: 0.4
Owner: changed from anonymous to alex

comment:2 Changed 13 years ago by bill

Cc: aaronmevans@… added
Summary: Add ability to set intial values of ComboBox inline[patch] Add ability to set intial values of ComboBox inline

Hi Aaron? Did you get notification that dojo foundation had received your CLA? Also, for patches we need a patch file (you can make one with "svn diff" or menu options from the various SVN clients).

Note that Combobox has changed a lot recently.

comment:3 Changed 13 years ago by dylan

Summary: [patch] Add ability to set intial values of ComboBox inline[patch][cla] Add ability to set intial values of ComboBox inline

cla verified.

comment:4 Changed 13 years ago by dylan

Owner: changed from alex to tk

we need to get this patch updated and the changes merged in.

comment:5 Changed 13 years ago by tk

Cc: ktiedt@… added
Status: newassigned

Aaron,

Could you please update this to work with latest SVN? If possible a .patch or .diff would be nice, but I'm not picky. :)

One thing to note is that ComboBox?.js now resides in /src/widget/ not /src/widget/html/ , the other form widgets should provide good examples on what needs changing.

Thanks for the help on this!

-Karl

comment:6 Changed 13 years ago by dylan

Milestone: 0.40.5

out of time for 0.4, will make into head just after that.

comment:7 Changed 13 years ago by aaronmevans@…

Hey guys, sorry, somehow I lost this thread of mail in my gmail so I thought there was nothing happening with this until I checked today.

I don't see where I can attach the patch file to this note, but I'll see if I can after I post this...

Changed 13 years ago by aaronmevans@…

Attachment: ComboBox.patch added

Patch for ComboBox?

comment:8 Changed 13 years ago by aaronmevans@…

ah, I see, it was up above.

Anyhow, a patch file is now attached (ComboBox?.patch). I put my changes against ComboBox?.js from SVN head.

cheers, aaron

Changed 13 years ago by aaronmevans@…

Attachment: Select.patch added

This Select.patch goes with ComboBox?.patch (patches setAllValues)

comment:9 Changed 13 years ago by bill

Owner: changed from tk to bill
Status: assignednew

I'll take this one over. Initial value setting is very complicated. There's already a way of setting the initial value if the data is inlined into the HTML page (same way that you set the value for a plain HTML <select> element). But for other data providers it gets more complicated, especially for incrementalDataProvider.

The thing is that maybe you only have the value (the hidden value), like "CA", not the (displayed) label, like "California". So in the same way that we want to support

   mySelectWidget.setValue("CA");

We want to support

  <div dojoType=Select value="CA">

to set the initial value. See also bug #1504.

comment:10 Changed 12 years ago by Douglas Hays

Owner: changed from bill to Douglas Hays

comment:11 Changed 12 years ago by csawyer@…

Attached is my 'fix' for this, it really doesn't solve the issue, but does provide a work around in a way, by allowing you to set a value, or defaultValue. No protocol change needed for this patch..

Changed 12 years ago by csawyer@…

Attachment: ComboBoxValuePatch.diff added

Patch file to add value (and defaultValue).

Changed 12 years ago by csawyer@…

Attachment: ComboBoxValuePatch.2.diff added

[ccla] Patch file to add value (and defaultValue). total workaround

comment:12 Changed 12 years ago by haysmark@…

Autocompleter now supports the format Bill mentioned. You just set the value attribute in the HTML to the hidden value you want to load with.

comment:13 Changed 12 years ago by Douglas Hays

Resolution: fixed
Status: newclosed

(In [8352]) Port of ComboBox?(=AutoCompleter?) and Select widgets to 0.9 dojo by haysmark@…. Fixes #2189, #1504, #1451, #2244, #2384, #2070, #899, #912, #1267, #1339, #1456, #1484, #1485, #2558, #1186

Note: See TracTickets for help on using tickets.