Search code examples
castle-monorail

MonoRail - Server-side vs. Client-side Form Validation


I'm using MonoRail and was wondering how it decides when to use client-side vs. server-side validation? In my model class I have [ValidateNonEmpty] on two properties, one is a textbox, the other is a dropdown. The textbox triggers client-side validation on form submission, if I leave the dropdown empty though it posts back to the server and returns back the validation error from server-side. Is there a way to get the dropdown to trigger client-side validation? Also it's odd because after the postback, it clears what I had entered in the dropdown but maintains the state of the textbox (viewstate anyone??)

Thanks, Justin


Solution

  • It viewed source and I saw that it was using jQuery for the client-side validation. It had:

    "business.businesstype.id":{ required: "This is a required field" }, 
    

    for the dropdown, which wasn't working. I noticed that it was using 0 as the default dropdown value so I manually put in firstoptionvalue and that got it working:

    $FormHelper.Select("business.businesstype.parent.id", $businessTypes, "%{value='id', text='name', firstoption='Select a Business Type', firstoptionvalue=''}")