Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mads Krohn 211 posts 501 karma points c-trib
    Apr 04, 2013 @ 12:41
    Mads Krohn
    0

    Client side validation

    In the Form.cshtml a partial is used to generate the required scripts for client side validation:

    @Html.Partial(FormViewResolver.GetScriptView(Model.FormId), Model)

    However, the scripts generated have dependencies on jQuery among others. Now, good practice is to put your scripts in the bottom of the html document, just before the closing body tag.

    I figured I could just move the snippet to a layout page and render the partial there, but I'm having troubles getting t he FormId required to render the partial. What is the recommended approach here?

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Apr 04, 2013 @ 12:58
    Tim Geyssens
    0

    It's a current workitem in our issue tracker http://issues.umbraco.org/issue/CON-271 to add an easy way of making it possible to add the scripts to the bottom or your page, will see if I can make some progress on it today and report back

  • Mads Krohn 211 posts 501 karma points c-trib
    Apr 04, 2013 @ 13:04
    Mads Krohn
    0

    Ok, that would be very nice. In the meantime, are there any workarounds? Like a way to get FormIds for a given page?

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Apr 04, 2013 @ 13:07
    Tim Geyssens
    100

    Well you'll have to build the form model and then pass it to, haven't tested this but try

    var Model =  new Umbraco.Forms.Mvc.Models.FormViewModel();

    Model.FormId = CurrentPage.formPickerProperty

    Model.Build();

    @Html.Partial(FormViewResolver.GetScriptView(Model.FormId),Model)
  • Mads Krohn 211 posts 501 karma points c-trib
    Apr 04, 2013 @ 15:30
    Mads Krohn
    0

    Yeah, was thinking about something like that. My only issue is that I'm inserting the form in a RTE field. However, I found a solution :)

    Btw, have you considered updating jQuery etc. to newer versions?

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Apr 04, 2013 @ 15:38
    Tim Geyssens
    0

    Haven't tried but think it's save to update them to a newer version on your frontend

  • Mads Krohn 211 posts 501 karma points c-trib
    Apr 04, 2013 @ 15:52
    Mads Krohn
    0

    Yeah, thought so too, and it almost is :)

    Only problem seems to be jQuery 1.9.x, where stuff starts to break.
    When using jQuery 1.9.1 I get the following error when submitting a form:

    Uncaught SyntaxError: Unexpected token u

    Which seems to normally be an indication that a value given to JSON.parse is undefined. From what I can gather, jQuery in version 1.9.x and forward correctly throws an error instead of silently swallowing it. So, I'm assuming, that for some reason Contour is trying to parse something that is undefined. Unfortunately that means I'm forced to run jQuery 1.8.3. Guess it will have to do for now.

  • Tim Geyssens 6562 posts 15373 karma points MVP 2x c-trib
    Apr 05, 2013 @ 10:48
    Tim Geyssens
    0

    Ok thanks for the details will add this to our issue tracker http://issues.umbraco.org/issue/CON-323

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies