Not able to select item
Good night,
I'm begining using comboBox and I'm not able to select an item. If I click in the item, the text stays empty. I'm using an Enum for the value. I'm sending my code bellow.
@using Syncfusion.Blazor.DropDowns
<div class="col-sm-12 col-md-12 col-lg-2">
<SfComboBox PopupHeight="230px" Placeholder="Tipo Pessoa" TValue="TipoPessoa" TItem="TipoPessoaModel" @bind-Value="@tipoSelecionado" DataSource="@tiposPessoa">
<ComboBoxFieldSettings Text="Descricao" Value="Tipo"></ComboBoxFieldSettings>
</SfComboBox>
</div>
@code{
public class TipoPessoaModel
{
public TipoPessoa Tipo { get; set; }
public string Descricao { get; set; }
}
public enum TipoPessoa
{
Juridica = 0,
Fisica = 1
}
public TipoPessoa tipoSelecionado;
List<TipoPessoaModel> tiposPessoa = new List<TipoPessoaModel>
{
new TipoPessoaModel{Tipo = TipoPessoa.Juridica, Descricao = "Jurídica"},
new TipoPessoaModel{Tipo = TipoPessoa.Fisica, Descricao = "Física"},
};
}
<div class="col-sm-12 col-md-12 col-lg-2">
<SfComboBox PopupHeight="230px" Placeholder="Tipo Pessoa" TValue="TipoPessoa" TItem="TipoPessoaModel" @bind-Value="@tipoSelecionado" DataSource="@tiposPessoa">
<ComboBoxFieldSettings Text="Descricao" Value="Tipo"></ComboBoxFieldSettings>
</SfComboBox>
</div>
@code{
public class TipoPessoaModel
{
public TipoPessoa Tipo { get; set; }
public string Descricao { get; set; }
}
public enum TipoPessoa
{
Juridica = 0,
Fisica = 1
}
public TipoPessoa tipoSelecionado;
List<TipoPessoaModel> tiposPessoa = new List<TipoPessoaModel>
{
new TipoPessoaModel{Tipo = TipoPessoa.Juridica, Descricao = "Jurídica"},
new TipoPessoaModel{Tipo = TipoPessoa.Fisica, Descricao = "Física"},
};
}
SIGN IN To post a reply.
5 Replies
BC
Berly Christopher
Syncfusion Team
March 27, 2020 12:50 PM UTC
Hi Társis,
Greetings from Syncfusion support.
While checked the provided code example, you have bound the Enum class for TValue in the Combobox component. In this case, the provided value’s key pair in the Enum class will be set to the component as integer through data source.
At that time of selecting the value from the popup, actual value integer will not be converted to the TValue type and script error will be thrown. So, the selected value not set to the component and displayed empty text in the input element.
Hence, we suggest you to set the int? for the TValue and convert the value in the data source as int? as mentioned in the below code example since you have defined the integer values in the Enum class.
|
<div class="col-sm-12 col-md-12 col-lg-2">
<SfComboBox PopupHeight="230px" Placeholder="Tipo Pessoa" TValue="int?" @bind-Value="@tipoSelecionado" TItem="TipoPessoaModel" DataSource="@tiposPessoa">
<ComboBoxFieldSettings Text="Descricao" Value="Tipo"></ComboBoxFieldSettings>
</SfComboBox>
</div>
@code{
public class TipoPessoaModel
{
public int? Tipo { get; set; }
public string Descricao { get; set; }
}
public enum TipoPessoa
{
Juridica = 0,
Fisica = 1
}
public int? tipoSelecionado;
List<TipoPessoaModel> tiposPessoa = new List<TipoPessoaModel>
{
new TipoPessoaModel{Tipo = (int)TipoPessoa.Juridica, Descricao = "Jurídica"},
new TipoPessoaModel{Tipo = (int)TipoPessoa.Fisica, Descricao = "Física"},
};
} |
Please find the sample with modified code from the below link.
Sample Link: https://www.syncfusion.com/downloads/support/forum/152762/ze/Blazor_latest_152762_enum-1956280943
Regards,
Berly B.C
TÁ
Társis
March 27, 2020 03:49 PM UTC
Thank you for your answer. It worked. So, actually it won't work with Enums, correct?
BC
Berly Christopher
Syncfusion Team
March 30, 2020 12:45 PM UTC
Hi Társis,
We would like to inform you that, if we binding the ENUM values with object types in the list instead of assign it directly, we need to convert it based on the provided value’s type in the value filed and assign to the component. So, we suggest you to bind the ENUM values directly like string array as mentioned in the below
documentation to work it out correctly.
UG Link: https://blazor.syncfusion.com/documentation/dropdown-list/data-source/?no-cache=1#enum-data-binding
Regards,
Berly B.C
JD
Jan De Wilde
June 16, 2020 07:31 AM UTC
Hi
I would like to bind to an Enum. I copied the example stated here:
UG Link: https://blazor.syncfusion.com/documentation/dropdown-list/data-source/?no-cache=1#enum-data-binding
But this doesn't work. I get the folowing error:
Cannot convert from 'string[]' to 'System.Collections.Generic.IEnumerable<Values>'
Are enums still supported?
Thanks
BC
Berly Christopher
Syncfusion Team
June 17, 2020 10:31 AM UTC
Hi Jan,
Sorry for the inconvenience caused.
We would like to inform you that ENUM values are supported in the DropDownList. So, we have created the sample with modified code based on the documentation and attached it below.
Sample Link: https://www.syncfusion.com/downloads/support/forum/152762/ze/DropDownList_ENUM_152762576324821
|
@using Syncfusion.Blazor.DropDowns;
<SfDropDownList TValue="Values" TItem="string" Placeholder="e.g. Australia" DataSource="@EnumValues" @bind-Value="@ddlVal">
</SfDropDownList>
@code{
public IEnumerable<string> EnumValues = Enum.GetNames(typeof(Values));
public Values ddlVal { get; set; } = Values.Canada;
public enum Values
{
Australia,
Bermuda,
Canada,
Denmark,
India,
US
}
} |
Also, we will correct the documentation with working code and refresh in the online soon.
Regards,
Berly B.C
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
TÁ Társis
- Mar 26, 2020 11:47 PM UTC
- Jun 17, 2020 10:31 AM UTC