Jump to content
Adamhumbug

Modal Population Only Correct First Time

Recommended Posts

<a id="callDeleteUserConf" class="btn btn-danger" data-toggle="modal" data-userid="8" data-activesheets="" href="#userDeleteConfirmationModal" data-firstname="First Name" data-lastname="Last Name">

Yes its the right thing

Edited by Adamhumbug

Share this post


Link to post
Share on other sites

So to be absolutely clear, your code is

var button2 = $(event.relatedTarget)
console.log(button2[0]);
console.log(button2.data('userid'))
console.log(event.relatedTarget)

and the first and third outputs show two different elements?

Share this post


Link to post
Share on other sites
16 hours ago, requinix said:

So to be absolutely clear, your code is


var button2 = $(event.relatedTarget)
console.log(button2[0]);
console.log(button2.data('userid'))
console.log(event.relatedTarget)

and the first and third outputs show two different elements?

So i copied what you have above directly into my code and have selected one user, backed out and selected another, here are the console logs that i get.

My code to show second modal

$('#userDeleteConfirmationModal').on('show.bs.modal', function(event) {
		// Button that triggered the modal
		var button2 = $(event.relatedTarget)
		console.log(button2[0]);
		console.log(button2.data('userid'))
		console.log(event.relatedTarget)
		//data elements
		var userid = button2.data('userid')
		var firstname = button2.data('firstname')
		var lastname = button2.data('lastname')
		var activesheets = button2.data('activesheets').split(", ").join("<br/>")
		var modal = $(this)
		modal.find('#deleteUserConfLabel').text(firstname + ' ' + lastname)
		modal.find('#active-sheets-label').text('This user has the following active sheets')
		modal.find('#active-sheets').html(activesheets)
		modal.find('#staffMemberId').val(userid)


		});

First Try

first modalhttps://adamhumbug.co.uk/user-list.php#userModal

2

<a id="callDeleteUserConf" class="btn btn-danger" data-toggle="modal" data-userid="2" data-activesheets="A new event, Chelsea's Event" href="#userDeleteConfirmationModal" data-firstname="Chelsea" data-lastname="Hockley">

2

<a id="callDeleteUserConf" class="btn btn-danger" data-toggle="modal" data-userid="2" data-activesheets="A new event, Chelsea's Event" href="#userDeleteConfirmationModal" data-firstname="Chelsea" data-lastname="Hockley">

Second Try

first modalhttps://adamhumbug.co.uk/user-list.php#userModal

8

<a id="callDeleteUserConf" class="btn btn-danger" data-toggle="modal" data-userid="8" data-activesheets="" href="#userDeleteConfirmationModal" data-firstname="First Name" data-lastname="Last Name">

2

<a id="callDeleteUserConf" class="btn btn-danger" data-toggle="modal" data-userid="8" data-activesheets="" href="#userDeleteConfirmationModal" data-firstname="First Name" data-lastname="Last Name">

Share this post


Link to post
Share on other sites

...ah.

IDs need to be unique on the page. Get rid of the one you have there and apply your event handler using some other selector.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.