0

Suppose I wanted to setup iFrame validation rules using jQuery Validation on the same domain (so no cross-site conflicts)

e.g.

jQuery('form#post').validate({

//Enforce iFrame rules here. 
)};

Within the iFrame I would have:

<iframe ...>
    <form method = "post" action ="..." class ="media-upload-form" id = "image-form">
    ...
    <input type="submit" name="send" id="send" class="button" value="Insert into Post">

    </form>
</iframe ...>

Inorder to do this

  1. What would I put within jQuery('???').validate?

  2. What if outside the context of the iFrame within the page there is another submit form that exists inside the DOM. Would jQuery().validate trigger that and how can I specify jQuery.validate to work inside the iFrame?

Jebathon
  • 4,310
  • 14
  • 57
  • 108
  • **There are no special settings or options for this**. The `iframe` is loading a "self-contained" page from elsewhere, so create your remote page just like any other page including jQuery Validate. – Sparky Jun 02 '15 at 14:51
  • [After reading this](http://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page), I think you're better off putting the jQuery for the `iframe` within the page that's loaded in the `iframe` rather than within the parent. Why would you want to do this anyway? `iframes` are ugly/nasty things, and since all content is located on the same site, there is no good reason or advantage for this method. Simply use jQuery to dynamically load new content and/or manipulate the DOM and avoid using the `iframe` element entirely. – Sparky Jun 02 '15 at 15:01
  • @Sparky Within Wordpress if you want to add media through posts or meta boxes an iFrame must be inserted into the DOM. I am trying to invoke JS through that iFrame. See http://hubskills.com/wp-content/uploads/2012/08/add-media-overlay-popup-in-wordpress.jpg – Jebathon Jun 02 '15 at 15:21

1 Answers1

0

You can try something like this

JS:

var iframe = document.getElementById('id_description_iframe');

// Get the document within the <iframe>
var iframeDocument = iframe.contentDocument || frame.contentWindow.document;

//now using jQuery
jQuery(iframeDocument.body).find('form#post').validate({

})};
Gonsalo Sousa
  • 495
  • 4
  • 9