Part of the html is replaced with the result of an ajax call. During testing, I made that ajax call the exact same thing as what was replaced. The issue was that none of the JQuery UI and "onClick" stuff I had applied to the old html applied to the new one. I tried recalling the functions that applied it again, but it won't work. Strangely enough, it DOES work if I type it directly into the counsel of google chrome (the new-ajax-html gets effected by the JQuery commands).
This is my code, which includes the original setup of the html at the start (which works) and the second set up (which comes after all of the needed elements have been instantiated.):
function set_up() { // <-- if I call this function in the consul, it works.
$('.delete-button').click(function() {
var confirm = window.confirm("Are you sure you want to delete? After you save, this file will not be recoverable.")
if (confirm){
$(this).parent('.deletable-group').remove()
}
});
$('.field-default[data-multi="True"]').makeMulti();
$("input.field-input-date").datepicker();
alert("HERE!") //Is reached both times I call the function. So the code above is executing.
}
var options = {
target: '.server-response-box',
success: function() { //<--- Gets called when the ajax call goes through.
$('.needs-update').each(function( index ) {
url = "/field/1/" + $('.edit-wrapper').attr('data-entry-ID') + "/" + $(this).attr('data-field-id');
old_this = this
$.get(url,function(data){
$(old_this).replaceWith(data);
});
});
set_up(); // Tries to set everything up again.
},
beforeSubmit: function(arr, $form, options) {
}
};
$('#form').ajaxForm(options);
set_up(); //<-- sets it all up the first time.