+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Using jQuery validation and sitefinity

Using jQuery validation and sitefinity

3 posts, 0 answered
  1. Victor
    Victor avatar
    1 posts
    Registered:
    27 Mar 2013
    28 Aug 2013
    Link to this post
    Hi,
    I'm trying to use jQuery validation in a sitefinity MVC widget.
    The problem is, when the widget gets rendered sitefinity removes the <form> element.
    My widgets html looks like this example:
    <form id="form" method="post">
         <h1>FirstName</h1>
        <input type="text" value="" name="FirstName" id="FirstName" />
          ...
    </form>

    But when the page is rendered the widget html looks like this:
          <h1>FirstName</h1>
          <input type="text" value="" name="FirstName" id="FirstName" />

    As you can see, the html form has been removed so I'm not able to use jQuery validation.

    Why sitefinity removes the <form> element?
    Is there any way to avoid this behavior?

    Thanks.
    Victor.


  2. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    30 Aug 2013 in reply to Victor
    Link to this post
    Here is some good information about creating MVC widgets of that nature

    http://www.sitefinity.com/documentation/gettingstarted/creating-sitefinity-mvc-widgets-that-input-data
  3. Nayden Gochev
    Nayden Gochev avatar
    32 posts
    Registered:
    03 Nov 2014
    02 Sep 2013
    Link to this post
    Hello Victor,

    Are you using a Razor syntax for creating the view of the MVC widget ?
    in short if you are using in Hybrid mode the MVC widget should not contain a standard form tag but instead should be embedded in a web form.. only in pure MVC mode you may have a normal regular form.

    In anyway I recommend the following :
    - use Razor syntax
    - instead of using @using (Html.BeginForm()) you should use the @using (Html.BeginFormSitefinity()) with the adding ot @using Telerik.Sitefinity.UI.MVC at the beginning of the view. This way based on your mode automatically a normal form or a web form will be generated.

    You can watch this video for creating MVC widgets http://www.youtube.com/watch?v=KRm7kDskUjg

    I am guessing in your case you are in hybrid mode and you want to use a jquery validation like : $("#myform").validate(); ? correct ? However if you are in hybrid mode this means you basically have a big web form and you already have a surrounding <form method="post" action="" id="aspnetForm"> tag and you cannot have an another form inside this one.

    I advice you to first use Razor syntax and etc as explained above
    and second to make your validation like following :
    - to have a surrounding div ... with some class like .validate-div
    - to write a validate call like :
    $(".validate-div").validate({
      rules: {
        // simple rule, converted to {required:true}
        name: "required",
        // compound rule
        email: {
          required: true,
          email: true
        }
      }
    });

    and so on.



    Regards,
    Nayden Gochev
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
3 posts, 0 answered