Perform Custom Client Validation on Input Fields in Admins Editor View

Topics: Customizing Orchard, Writing modules
Jan 21, 2013 at 6:58 AM

I'm wondering how I would validate my input fields to match certain criteria before letting the Admin submit some values for my content part, for example I have:

@model Adverts.Models.AdvertPart
  <legend>Ad Fields</legend>

class="editor-label"> @Html.LabelFor(model => model.Field1)
class="editor-field"> @Html.TextBoxFor(model => model.Field1,new{id="Field1TextBox"}) @Html.ValidationMessageFor(model => model.Field1)
</fieldset> <script> Intercept form submission and prevent it if Field1TextBox's value is less than 8 characters long for example </script>

How would I prevent the user from adding submitting an undesired values for Field1, i.e. it must be more than 8 characters long.
Ideally I want to perform this client side. Thanks.

Jan 21, 2013 at 7:58 AM

Oops, my bad. It's just the same as any MVC project. I'd just forgotten to put 

    @using (Script.Foot()) {

Before my <script> section.