Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This may only be a partial answer to your question, if I understand it correctly. </p> <p>Regarding your example with <code>&lt;input type="text" class="date" /&gt;</code>, we experienced a similar issue with our partial form views that use jQuery unobtrusive validation. When loading them in the browser, we had to call <code>$.validator.unobtrusive.parse('a form selector');</code> in order to get the validation rules to apply during the next form submission. </p> <p>If your goal is to avoid repeated code, you could make your js actions unobtrusive, using a pattern like in the jq unobtrusive validation lib. So you would end up with HTML that looks more like this:</p> <pre><code>&lt;input type="text" class="date" data-datepicker="true" /&gt; </code></pre> <p>You can then put the initialization logic in an unobtrusive parse method.</p> <pre><code>parse: function(selector) { $(selector).find(':input[data-datepicker=true]').each(function() { $(this).datepicker(); } }; </code></pre> <p>}</p> <p>This solves your problem of having one place to refactor the code. You can make it start up automatically when the page first loads, and when you load new content via ajax, you can apply the rule to all matching elements by just calling <code>myAppNamespace.unobtrusive.parse('selector for the partial view content');</code></p> <p><strong>Update</strong></p> <p>Take a look at the jquery.validate.unobtrusive.js file in your scripts folder. It really is pretty smart, and if you're not actually extending another jquery plugin (like validate), your code would end up a lot slimmer. If you're looking for full separation of HTML and script, using the HTML5 unobtrusive data- attributes is a good solution imo.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload