trestle
trestle copied to clipboard
fire js event after dialog form is shown
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...
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)
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()