Nop 2.8 admin, how to display the "must not be empty" message?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
10 years ago
I've added two fields to product variant, and to the "create or update" on the admin page for product variant.

However, I cannot see how to make a field required and to display the "must not be empty" message.

I do have the @Html.ValidationMessageFor line, but don't know where that connects to the actual validation.

Thanks in advance.
10 years ago
mwoffenden wrote:
I've added two fields to product variant, and to the "create or update" on the admin page for product variant.

However, I cannot see how to make a field required and to display the "must not be empty" message.

I do have the @Html.ValidationMessageFor line, but don't know where that connects to the actual validation.

Thanks in advance.


You need to attach it with a validator. Look at ProductValidator.cs for example. :)
10 years ago
Ok, I got that working by adding a rule to ProductVariantValidator.cs.  

But I'm still puzzled about something.  On the product variant screen, "price" displays an error when there is no input.  But there is no rule in ProductVariantValidator.cs for price.

How does that error, 'Price' must not be empty, get generated, when there is no rule present?
10 years ago
mwoffenden wrote:
Ok, I got that working by adding a rule to ProductVariantValidator.cs.  

But I'm still puzzled about something.  On the product variant screen, "price" displays an error when there is no input.  But there is no rule in ProductVariantValidator.cs for price.

How does that error, 'Price' must not be empty, get generated, when there is no rule present?


The reason is simple. Price is of 'decimal' type. decimal is a struct, which makes it non-nullable. So 'not empty' rule is automatically applied. Just like decimal must be numbers, if you try to enter any alphabets you'll get into trouble. Because the 'number only' rules is automatically applied. :)
10 years ago
wooncherk wrote:
So 'not empty' rule is automatically applied.

Thanks for the explanation, however, the rule is automatically applied by what?  By the .NET framework?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.