HTML5 validation and ASP.net Webforms

前端 未结 2 467
逝去的感伤
逝去的感伤 2021-01-26 23:42

I\'m experimenting with HTML5 built-in validation attributes and the first difficulty I have run into is that the validation attributes work in a form context. I.E. if you want

相关标签:
2条回答
  • 2021-01-27 00:35

    Warning: The following solution isn't beautiful, I know. But it's the only solution I can think of. :/

    Create a form-tag side by side with the server-created form-tag. Position the client-side form on top of the page.

    Drawback: You cannot use server tags. But hey... who does now a days?! :)

    <form runat="server" ...>
        ... Everything ....
    </form>
    <div class="positionedOnTopOfThePage">
        <form>
            ... Form with HTML5 validation ...
        </form>
        <form>
            ... Form with HTML5 validation ...
        </form>
    </div>
    
    0 讨论(0)
  • 2021-01-27 00:38

    I think you have a misunderstanding.

    HTML 5 has both form and input validation attributes. The form attributes simply allow you to turn on/off autocomplete and completely turn off validation of all of the input elements.

    The input elements are where the real work is performed. Note that you can have autocomplete turned on at the form level, but have it turned off for particular inputs.

    BTW, having nested <form> tags is still a no no under HTML5. It's just that various browsers support it in order to continue to be compatible with the vast majority of sites that were coded incorrectly. Actually, this concept, of being as compatible as possible, is the leading reason browsers are so complicated.

    More info: http://www.w3schools.com/html5/html5_form_attributes.asp

    0 讨论(0)
提交回复
热议问题