PDA

View Full Version : [CLOSED] Combo box marks itself as required



registrator
Apr 01, 2015, 11:34 AM
I have a combo box defined as:


X.ComboBoxFor(m => m.GLOBAL_TAX_CODE).FieldLabel("Tax Code").LabelWidth(80).DisplayField("ComboDisplay").ValueField("TaxCodeID")
.ListConfig(Html.X().BoundList()
.ItemTpl(Html.X().XTemplate()
.Html(@<text>
<div class="list-item">
<h3>{Name} - Rate: {RATE}%</h3>
{DESCRIPTION}
</div>
</text>)
)
)
.Store(X.Store()
.ID("TaxCodeComboStore")
.AutoLoad(true)
.Model(
X.Model()
.Name("TaxCodeCombo")
.IDProperty("TaxCodeID")
.Fields(
X.ModelField()
.Name("Name")
.Type(ModelFieldType.String),
X.ModelField()
.Name("DESCRIPTION")
.Type(ModelFieldType.String),
X.ModelField()
.Name("RATE")
.Type(ModelFieldType.Float)
)
)
.Proxy(Html.X().AjaxProxy()
.Url(Url.Action("GetList", "List", new { area = "TaxCode" }))
.Reader(Html.X().JsonReader().Root("data"))
)
)


The model property is not marked as Required.
Yet, when I focus on the field and leave it becomes red and the message says it is a required field.
Where is this required condition coming from if I am not defining it specifically for this field?

Thank you

Daniil
Apr 01, 2015, 9:21 PM
Hi @registrator,

Please post a definition of the m.GLOBAL_TAX_CODE property.

registrator
Apr 02, 2015, 10:08 AM
[DisplayName("Global tax code")]
[Range(0, 99, ErrorMessage = "Value must be maximum 2 characters")]
public int GLOBAL_TAX_CODE { get; set; }

Daniil
Apr 02, 2015, 10:41 AM
Thanks.

"int" is not a Nullable type. By default, it is treated like there must be a value. So, a ComboBox's AllowBlank turns to false by default.

You can set .AllowBlank(true) explicitly.

registrator
Apr 02, 2015, 11:41 AM
Thank you.