Announcement

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

    Setting displayField and valueFields using custom editors

    How do you set the displayValue of a field independently from the actual value for fields that have an optionDataSource with valueField and displayField specified?

    I wrote a custom editor using your YesNoMaybe editor as a template.

    The function that gets called when the user makes a selection in the field editor is:

    // set the specified value and dismiss the picker dialog
    setSelection : function (record) {
    this.currentEditor.setValue(record.name);
    this.dialog.hide();
    this.dialog.markForDestroy();
    this.dialog = null;
    }

    In this case currentEditor.setValue(record.name) sets the actualValue and the displayValue together. The record also has record.id that I need to use as the field value while the record.name gets displayed.

    Thanks,
    paul

    #2
    Hi Paul,

    Do you mean that you have a display value in mind that differs from the value found in the displayField of records from the optionDataSource? Maybe a display value that incorporates information from multiple fields?

    If so, you can use a valueMap in combination with the optionDataSource. In this case the valueMap acts like a local cache of specific id->displayValue mappings.

    So for example, in your setSelection() function, you might do something like:

    Code:
        var valueMap = {};
        valueMap[record.id] = record.name + " (" + record.id + ")";
        this.currentEditor.setValueMap(valueMap);
        this.currentEditor.setValue(record.id);

    Comment


      #3
      Actually, my question is about who's responsibility is it to actually set displayField values and valueField values when writing a custom editor. If you use a builtin editor such as a PickList and the field has an optionDataSource, the PickList editor know how to set the displayValue separately from the valueField value. Since I've written a custom editor I assume its the custom editor's responsibilty to set these 2 values separately on the related field - or at least that's the impression I got from the YesNoMaybe example provided.

      The field record has an record.id (valueField) and record.name (displayField). I just wanted to know how to manually set these 2 values within the custom editor code that gets called when the user makes a selection.

      The published API's for the FormItem only includes:
      setValue(fieldValue)
      getValue()
      getDisplayValue()

      but no setDisplayValue(value)

      -paul

      Comment


        #4
        To manually manage display value, the setValueMap API demonstrated in the previous post is the right API. However note that support for automatically managing display value via an optionDataSource is not actually limited to PickList-based FormItems - see FormItem.fetchMissingValues.

        Comment


          #5
          Thanks. The recommended API works fine.

          -paul

          Comment

          Working...
          X