Using jQuery validation and sitefinity

Posted by Community Admin on 04-Aug-2018 17:39

Using jQuery validation and sitefinity

All Replies

Posted by Community Admin on 28-Aug-2013 00:00

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.


Posted by Community Admin on 30-Aug-2013 00:00

Here is some good information about creating MVC widgets of that nature

www.sitefinity.com/.../creating-sitefinity-mvc-widgets-that-input-data

Posted by Community Admin on 02-Sep-2013 00:00

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

This thread is closed