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

Forums / Developing with Sitefinity / ASP.NET MVC Validation

ASP.NET MVC Validation

2 posts, 0 answered
  1. Nick
    Nick avatar
    15 posts
    Registered:
    30 Oct 2013
    26 May 2014
    Link to this post

    Hi all,

    I have a quick question regarding MVC validation within MVC widgets.  I've noticed that on-submit validation works beautifully - the form gets sent, fails to validate and I can show any relevant messages for the user to correct.

    I was wondering if there's any support for the inline validation that MVC would normally allow - where each field is validated on the fly rather than on submit?

     

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    07 Dec 2016
    27 May 2014
    Link to this post
    Hello Nick,

    Along with your server-side validation, you can add a client-side validation by using for example JavaScript, where to add a violation message and/or to hide/deactivate the submit button (example).

    Below is the sample code used in the View:
    <script>
        function test() {
            var name = document.getElementById('name').value;
            console.log(name.length);
            if (name.length >= 3) {
                document.getElementById('err1').setAttribute("style", "display: none");
            }
            else {
                document.getElementById('err1').setAttribute("style", "color:red; display: inline-block");
            }
        }
    </script>
     
    <form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
        First name:
        <input type="text" name="fname" onchange="test()" id="name">
        <span id="err1" style="display:none">Please enter at least 3 charecters</span>
        <br />
        <input type="submit" value="Submit">
    </form>

    You could check the proposed solution in that forum post also.

    Regards,
    Svetoslav Manchev
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered