XF 2.0 Possible to change data-xf-click dynamically?

mjda

Well-known member
Here's what I have:

Code:
<a href="{{ link('threads/quick-feature', $thread) }}"
	class="menu-linkRow"
	data-xf-click="switch"
	data-menu-closer="true">

	<xf:if is="$thread.scu_ft_featured">
		{{ phrase('scu_ft_unfeature_thread') }}
	<xf:else />
		{{ phrase('scu_ft_feature_thread') }}
	</xf:if>
</a>

So what I'm wondering is if it's possible to somehow change the data-xf-click option to "overlay" when the text is switched from Unfeature thread to Feature thread?

What I'm wanting to do is if the user is unfeaturing a thread it will just show the 'your changes have been saved' message then also change the link text to "Feature thread". This works fine when data-xf-click="switch".

However, when someone is featuring a thread I need to show a form so some extra data can be input. This works fine when data-xf-click="overlay".
 
HTML:
<xf:if is="$thread.scu_ft_featured">
    <a href="{{ link('threads/quick-feature', $thread) }}"
    class="menu-linkRow"
    data-xf-click="switch"
    data-menu-closer="true">
        {{ phrase('scu_ft_unfeature_thread') }}
    </a>
<xf:else />
    <a href="{{ link('threads/quick-feature', $thread) }}"
    class="menu-linkRow"
    data-xf-click="overlay"
    data-menu-closer="true">
        {{ phrase('scu_ft_feature_thread') }}
    </a>
</xf:if>
 
HTML:
<xf:if is="$thread.scu_ft_featured">
    <a href="{{ link('threads/quick-feature', $thread) }}"
    class="menu-linkRow"
    data-xf-click="switch"
    data-menu-closer="true">
        {{ phrase('scu_ft_unfeature_thread') }}
    </a>
<xf:else />
    <a href="{{ link('threads/quick-feature', $thread) }}"
    class="menu-linkRow"
    data-xf-click="overlay"
    data-menu-closer="true">
        {{ phrase('scu_ft_feature_thread') }}
    </a>
</xf:if>

Yes, but when I do that the data-xf-click doesn't change to overlay when I unfeature a thread. So, if I unfeature a thread then try to feature one without refreshing the page the data-xf-click="switch" still and my form is never displayed.
 
This one will trigger overlay on any click.
HTML:
<a href="{{ link('threads/quick-feature', $thread) }}"
    class="menu-linkRow"
    data-xf-click="switch overlay"
    data-menu-closer="true">

    <xf:if is="$thread.scu_ft_featured">
        {{ phrase('scu_ft_unfeature_thread') }}
    <xf:else />
        {{ phrase('scu_ft_feature_thread') }}
    </xf:if>
</a>

If you need more advanced click handling then I'd suggest writing two custom click handler functions one of which would watch for class change and then open an overlay and the other one would change the class based on your criteria (you can combine them into one handler if you want). You can read more about it here: https://xenforo.com/community/threa...ment-updates-from-xf2demo.139565/post-1205088
 
Back
Top Bottom