trestle icon indicating copy to clipboard operation
trestle copied to clipboard

fire js event after dialog form is shown

Open okliv opened this issue 6 years ago • 2 comments

hi!

i have a form with dialog: true enabled

form dialog: true do |instance|

and i need to fire some js after bs modal is fully loaded

but if i try to do it according to bs manuals with

$('#dialog').on('shown.bs.modal', function (e) { $('.some.form.input').mod() })

or with

$(document).on('shown.bs.modal', '#dialog', function (e) { $('.some.form.input').mod() })

nothing happens...

it is because form elements are loading with ajax after modal is shown with preloader (?). but i can't figure how to access form in it's complete state... looking forward for solution...

okliv avatar Jun 02 '18 15:06 okliv

i can assume that this question can be defined as not trestle specific problem but as far as i discovered there is no way to directly access external modal content load success event...

meantime, ugly working solution is (in my case):

$(document).on('shown.bs.modal', '#dialog', function (e) {
    $(document).one('ajaxSuccess', function () {
          $('.some.form.input').mod()
    })
})

can it be better? (i can imagine some trestle specific function to run custom code after modal is fully loaded)

okliv avatar Jun 02 '18 16:06 okliv

Hi! The best option is to respond to Trestle.init(function(e, document_root)){ ..... }); event. With your code, simply call $('.some.form.input', document_root).mod()

lphm avatar Mar 03 '20 15:03 lphm