I am trying to create a SelectItem subclass with some customized pickList properties. According to documentation pickList is an AutoChild so something like this should work:
You’re right - the pickList is constructed in a special way and doesn’t appear to pick up pickListDefaults.
You can set pickListProperties and things should work, or you can define a subclass of PickListMenu and apply that using pickListConstructor.
We’ll revisit this with our development team.
One more note: The bodyBackgroundColor may not be the best test to quickly see if customization worked, since default pickList styling will typically have background color specified for each cell, meaning the underlying color only shows through if there is empty space below the last row - rare for a pickList which sizes to its content.
Edited to add: Just for context, SmartClient has a number of multi-pickers for different situations, including the standard SelectItem with multiple:true, the MultiComboBoxItem, the SetFilterItem and the MultiPickerItem. If your goal is to create a multi-picker to support behavior that isn’t available out of the box, please let us know what you’re missing in case it’s already supported in some way
Thanks for looking into this. I used bodyBackgroundColor for my example because it is visible in online showcase, just enough to show the issue.
My picker customization is pretty simple:
I add a workaround for selected records being lost when dataSource contains over ~100 items
when pick list uses checkboxes I make item labels clickable so that users aren’t required to click on small boxes
The entire class looks currently like this:
declare namespace isc {
// TODO: patch smartclient.d.ts, SelectItem should inherit form FormItem, but it doesn't
class MultiSelectItem extends SelectItem {}
}
isc.defineClass("MultiSelectItem", "SelectItem").addProperties({
multiple: true,
defaultPickListProperties: {
// dataFetchMode:basic is required so that, with a long value list, we won't remove a previously selected
// item that isn't currently fetched (i.e. frontend doesn't know about it)
dataFetchMode: "basic",
recordClick(_viewer, record, _recordNum, field, _fieldNum, _value, _rawValue) {
if (this.selectionAppearance === "checkbox" && !this.isCheckboxField(field)) {
if (this.isSelected(record)) {
this.deselectRecord(record);
} else {
this.selectRecord(record);
}
}
return this.Super("recordClick", arguments);
}
},
init() {
// this should be done with isc.MultiSelectItem.changeDefaults("pickListDefaults", ...) but it doesn't seem to work:
// https://forums.smartclient.com/forum/technical-q-a/277011-cannot-set-picklistdefaults-on-a-selectitem
this.pickListProperties = isc.addProperties({}, this.defaultPickListProperties, this.pickListProperties)
this.Super("init", arguments)
},
transformInput: (_form, _item, value, _oldValue) => {
// SelectItem with multiple:true can sometimes return 'null' when no item was selected, which would get changed
// to en empty string, and then converted to an array with an empty string, and we don't want that
return value == null ? [] : value
}
});
This absolutely should not be required. A databound SelectItem with multiple:true should behave correctly out of the box no matter how many records you have in your data set. You can try this out by pasting the following code into the showcase (for example here: https://smartclient.com/smartclient/showcase/?id=comboListComboBox)
This data set has ~4000 records and you can select items from anywhere in the list without losing the selection.
If you have a case where this is broken we would be interested to see what’s going on for you.
Thanks for the test case - we’ll take a look
Also we’ve modified the codebase to support pickListDefaults for SelectItems and ComboBoxItems and ported the change back to 13.1 so this pattern should work for you with nightly builds going forward (Jan 21 and above)
Hi Crack
A quick follow up on the “lost values issue”
The fundamental issue with having a multi-select with a large data set that may not be fully loaded is that if the value has already been set to include some value(s) that are not in the data set, it is impossible for a user to clear those values. At best the user would have to scroll and search for the values in later pages of data, and at worst the pickListCriteria might be configured such that the previous values are not present at all, making it truly impossible to clear them.
Therefore when the user changes selection, the item will update to match what’s actually selected in the list rather than adding to the previous selection (including values that don’t map to any loaded record in the pick list).
Turning off data paging for the item at the application level to ensure the entire data set is loaded in this scenario makes sense, assuming you can assert that the data set will not be unmanageably large.
As a more general pattern we recommend using the MultiPickerItem instead of a SelectItem when you have a very large data set and need multi selection as this component has been designed to handle this and provides a better user experience.
We will update the documentation to make this clearer and we’ll ensure a warning is logged in the case where a SelectItem with multiple:true has its value set to something that isn’t in the data set and so will be dropped when the user updates the pickList selection.