Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Questions about "allowEmptyValue" in ComboBoxItem

    Hi,

    We have a question about ComboBoxItem. For SelectItem, if we set "allowEmptyValue" to be true, there will be an empty option in the drop down list. For ComboBoxItem, setting "allowEmptyValue" won't achieve the same behavior, since from the documentation the function of this property seems different from that for SelectItem .

    We are wondering if there is any way to achieve the same behavior (an empty option in the drop-down list) for a ComboBoxItem. We are using SmartClient v8.3p_2014-10-18 build.

    Thanks!
    Robin

    Code:
    isc.DynamicForm.create({
        width: 500,
        fields: [
    	{allowEmptyValue: true, title: "Ship to", type: "ComboBoxItem", valueMap: ["A","B"]},
    	{allowEmptyValue: true, title: "Ship from", type:"select", valueMap:["A","B"]}
        ]
    });

    #2
    I asked about this before with this post:
    http://forums.smartclient.com/showthread.php?t=29344

    Comment


      #3
      Ironically... I came here to ask some additional questions. I think it may be useful to your situation as well.

      We got around this (partially) by doing something like this in our app:
      Code:
      isc.SelectItem.addProperties( {
      		showClearIcon: true,
      		init: function() {
      			if ( this.showClearIcon ) {
      				var clearIcon = {
      					prompt: "Clear", hspace: 0, height: 22, width: 18, showOver: true,
      					src: "[skin]/images/pickers/clear_picker.png",
      					click: function ( form, item, icon ) {
      						item.storeValue(null, true);
      					}
      				}
      
      				if ( this.icons ) {
      					this.icons.push ( clearIcon );
      				} else {
      					this.icons = [ clearIcon ];
      				}
      			}
      
      			this.Super("init", arguments);
      		}
      	});
      However, we are now running into another little issue that I recall running into a while back.

      clearValue() does not call change() or changed() callback. This means if you have other UI elements that want to look for something like:
      "Whenever the value of this element changes", you need to look for 2 things.... changed, and clearValue.

      However, for dropdowns that have allowEmptyValue:true, selecting that "empty value" from the list DOES call change and changed.

      So the question for us is... how can we get our custom icon to clearValue or setValue(null) the same way that the built-in allowEmptyValue:true works so that it not only clears the value, but it also triggers the change and changed event?

      Finally, calling clearValue() or setValue(null) will automagically change the value of the item to whatever is set as the defaultValue for the item... but selecting the emptyValue that is built into the dropdown does not do this behavior... which makes me think this emptyValue is kind of doing something else completely different behind the scenes.

      Either way, it seems inconsistent.

      1) What, problematically, is happening when a user selects the "emptyValue" from a dropdown when allowEmptyValue is set to true? Is there a way for us to mimic / duplicate this functionality with a custom icon on the FormItem?
      2) If clearValue() and setValue(null) will actually cause an item to use the defaultValue (if it exists), why doesn't the "emptyValue" of a dropdown do the same thing?
      Last edited by amcculley; 28 Oct 2014, 08:49.

      Comment


        #4
        Hi All
        It seems like Rchu's original question may be about simple single-selection comboBoxItems rather than multi-comboboxes.

        In a standard comboBoxItem with allowEmptyValue set to true, we don't show the empty entry at the top of the pickList by default as this would be an unusual UI for a comboBoxItem. The user can simply select the text of the item and hit delete to clear it in the text box (and if you look at standard ComboBoxItem uses, such as the URL bar in a browser, there isn't usually a blank option shown at the top of the list of options).

        If you really want this within your app, you could customize the set of options shown in the pickList via the new 'specialValues' feature, or via custom data, either from a clientOnly optionDataSource, or an override of 'getClientPickListData'.

        RE amcculley's questions: There is a general difference between values chosen / entered by a user and values set programmatically by code. A user entered value will correctly fire change/changed handlers, etc whereas an explicitly set value will not.
        In general the storeValue() API is available as a way for developers to store a value as if the user had entered it (firing change handlers, etc)

        Regards
        Isomorphic Software

        Comment


          #5
          storeValue() works perfectly! Thank you.

          My response to the OP was to let him know a workaround that we have done to overcome the fact that a multi-select ComboBox does not have a "Select None" option to clear out all values.

          Comment


            #6
            Thanks very much for the answer. We will try the suggested ways in our application.

            Comment


              #7
              I updated my example code with the storeValue method instead of clearValue

              Comment

              Working...
              X