Post by Joe1234 » Thu Aug 01, 2024 5:20 am

I have a small javascript function that doesn't seem to be behaving normally. It is supposed to update the title of a button in the admin. The problem is it doesn't update the displayed title (when hovering) until the page is refreshed. I have sass and theme cache turned off. Other javascript stuff update without any issue, so I don't think it's a cache issue. Any thoughts?

Code: Select all

	<div class="pull-right" style="padding-right: 10px">
        <button type="button" data-toggle="tooltip" title="Delete All" class="btn btn-default hidden-md hidden-lg"><i class="fa fa-trash"></i></button>
        <a href="{{ delete_all }}" data-toggle="tooltip" id="buttondeleteall" title="Delete All" class="btn btn-danger"><i class="fa fa-trash"></i></a>
	</div>

Code: Select all

    <script>
        function setCookie(name, value) {
            const button = document.getElementById('buttondeleteall');
            button.setAttribute('title', 'Delete all ' + value + ' IPs');
            //alert('Button title updated to: ' + button.getAttribute('title'));
        }
    </script>
Last edited by Joe1234 on Fri Aug 02, 2024 1:04 pm, edited 1 time in total.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Thu Aug 01, 2024 4:08 pm

How are you calling the setCookie function and are you sure it's being called?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by paulfeakins » Thu Aug 01, 2024 6:42 pm

ADD Creative wrote:
Thu Aug 01, 2024 4:08 pm
How are you calling the setCookie function and are you sure it's being called?
Exactly this, it's probably not being called.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by Joe1234 » Thu Aug 01, 2024 10:18 pm

Code: Select all

<li class="active"><a href="#tab-ratelimit" data-toggle="tab" onclick="setCookie('tab', 'ratelimit')">{{ tab_1 }}</a></li>

Yes it's being called, already verified in the developer console...and also stated in OP, once the page is refreshed the change shows up.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Thu Aug 01, 2024 11:36 pm

If you inspect the element in the developer tool does the title actually change?

If you enter the following directly in the console, does it change?

Code: Select all

document.getElementById('buttondeleteall').setAttribute('title', 'Test');

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Fri Aug 02, 2024 12:29 am

Yes it shows it is changing in the console as soon as I click the tab.

I've never entered code directly in the console before, so I don't know if I entered it in the correct place, but here's a screenshot of where I did it and the result.

Attachments

Screenshot (174).png

Screenshot (174).png (34 KiB) Viewed 779 times


v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Fri Aug 02, 2024 1:38 am

Should be Id on the end not ID.

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Fri Aug 02, 2024 2:25 am

Right after typing the correction in and pressing ENTER under it pops up "undefined" and the actual button is not updated, but the info in the console shows the title changed.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by ADD Creative » Fri Aug 02, 2024 2:49 am

If it's a Bootstrap tooltip try the following or look at the Bootstrap documentation.

Code: Select all

document.getElementById('buttondeleteall').setAttribute('data-original-title', 'Test');

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by Joe1234 » Fri Aug 02, 2024 4:14 am

I actually tried that already. I noticed that attribute when I entered the information directly in the console. It didn't work.

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am

Post by nonnedelectari » Fri Aug 02, 2024 8:29 am

You realize that after setting a cookie, it is only returned on the next request, not instantanious.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by Joe1234 » Fri Aug 02, 2024 1:04 pm

Looks like the issue is with bootstrap. Here are two fixes.

Code: Select all

let button = document.getElementById('buttondeleteall');
$(button).attr('title', value).tooltip('fixTitle');
or

Code: Select all

let button = document.getElementById('buttondeleteall');
$(button).attr('data-original-title', value)

v3.0.3.9 php 8.1
I'm here for a reason, if your response is contact a/the developer, just don't reply.


Active Member

Posts

Joined
Sat Jan 01, 2022 5:47 am
Who is online

Users browsing this forum: No registered users and 28 guests