Hello,
I've been trying to use complex objects to bind to my multiselect dropdown component, but I'm struggling to see the values and bind the values OnPost event of my razor page (NOT MVC).
Some notes:
1) If I use simply array o string (string []), I can see all the values, bind them, and I click selecting multiple values, I can see that the values are selected.
2) If I use complex object, for example, the multiselect dropdown will be populated by a List<MyObject>, where I'm trying to do the following:
1.1)MyObject has several properties, and I'm using for the text and value property the same value, for example, MyObject has on property called string Feeling_Desc, where Desc will the value AND the text to be shown in the dropdown list. In this case, the drowdown populates correctly with the Desc values there (Desc1, Desc2, etc,). However after selecting the values when I click elsewhere in the page, change the focus to any other place in the page, the dropdown does not "indicates" the values are selected, even though if click on it again, it shows me the values I've selected.
2.2) On clicking on my button to submit the form, the OnPost event shows NULL for the List<MyObject> that was bound to the component in the OnGet event. My property has [Bindproperty] on it so I'm lost as what is going on.
<div class="col-sm-4">
<ejs-multiselect id="gutfeelingentrada" dataSource="@Model.gutFeelingsEntradaBind" ejs actionBegin="onBegin" dataBound="onBound" ejs-for="@Model.gutFeelingsEntradaBind" placeholder="Test" mode="Default">
<e-multiselect-fields value="MyObject.Feeling_Desc" text="MyObject.Feeling_Desc"></e-multiselect-fields>
</ejs-multiselect>
</div>
<script>
var selected = [];
function onBegin(e) {
this.fields = {
text: 'Feeling_Desc', value: 'Feeling_Desc', itemCreated: function (e) {
var count = 0;
if (count === 0) {
for (let i = 0; i < e.dataSource.length; i++) {
if (e.curData.isSelected == true)
itemSearch(e.curData.Code); //pass the corresponding value
}
}
}
}
}
function itemSearch(e) {
if (selected.indexOf(e) == -1)
selected.push(e);
}
function onBound(e) {
this.value = selected;
}
</script>
public class MyObject
{
public int TradingJournalFeelings_Num { get; set; }
public int? TradingJournalNum { get; set; }
public string FeelingType { get; set; }
public string Feeling_Desc { get; set; }
public bool isSelected { get; set; }
}
[BindProperty]
public List<MyObject>gutFeelingsEntradaBind { get; set; }
Could you please kindly help me?
Thanks,
Flavio