Skip to content

(List Dropdown) Setting selectedItem fails when value is a number and dataSource.value is numeric on HashLink #689

@NotHyper-474

Description

@NotHyper-474

In a project I'm trying to implement HashLink support there are list dropdowns which are dynamically generated based on a schema, and one of the schemas contains a map that looks like ['A' => 0, 'B' => 1], which gets turned into something like { text: 'A', value: 0 } in the dataSource.
The project tries to update the dropdown by setting the selected item, but it does so using the value, which works on the C++ target but not on hashlink.

The issue is that setting selectedItem will convert the value passed to it to a string if it's not a anonymous structure.

private override function set_selectedItem(value:Dynamic):Dynamic {
if (value == null) {
return value;
}
var text = null;
if (Type.typeof(value) == TObject) {
text = value.text;
if (text == null) {
text = value.value;
}
} else {
text = Std.string(value);
}
var index:Int = indexOfItem(text);
selectedIndex = index;
return value;
}

But indexOfItem compares the value with the one in dataSource disregarding the different type it now has (it was an int but now is a string, but value in dataSource is still an int). And in HXCPP for some reason having a:Dynamic = 2, b:String = "2", a == b will return true, but not on HL.

var item:Dynamic = _dropdown.dataSource.get(i);
if (item == text || item.value == text || item.text == text) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions