Reinitialize conditional logic javascript after page load?

Support MB Conditional Logic Reinitialize conditional logic javascript after page load?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #34021
    Stephen C.Stephen C.
    Participant

    Is there a way to reinitialize the conditional logic javascript after the page has loaded? Since conditional logic doesn't work with clones as it is, I have written some javascript to update the "data-conditions" attribute on the cloned element when a clone is generated. That works fine. The only issue is that the conditional logic script needs to be reinitialized for the clone's conditional logic to work.

    #34032
    Long NguyenLong Nguyen
    Moderator

    Hi Stephen,

    Please try to add this code to the file conditional-logic.js line 585

     // Export the runConditionalLogic to global scope to use in other scripts.
        rwmb.runConditionalLogic = runConditionalLogic;

    before the function setTimeout( init, 100 );, screenshot https://monosnap.com/file/rQP339lmZ4HCZg3byBWYjwRMKZ9aZM

    Then on your JS file, you can call it rwmb.runConditionalLogic( $scope ) where $scope is a jQuery element. If this works, I will inform the development team to add the code in the next update.

    #34038
    Stephen C.Stephen C.
    Participant

    I couldn't seem to get it to work. It might be because the script uses selector caching or I might be just doing something wrong. No big deal. The conditional I'm using is pretty simple, so it was easy to write a separate script to deal with the clones for that particular situation. Digging through the clone.js code, I did find the 'after_clone' event that's triggered, which makes it really easy to run code after a clone has been created. That's something you might want to include in your documentation somewhere. I'm sure others would find it useful.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.