How to use Switch to have effect on the View?

Support MB Views How to use Switch to have effect on the View?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #48901
    EddyPiVEddyPiV
    Participant

    Hi, I have a view where posts are displayed.
    I want to add a switch to include / exclude posts of a specific category.
    According tp the documentation a switch is stored in the database. That's fine, so I added a switch to the user profile, so that each user can switch on or off for his own view.

    My question:
    How can I use the switch to take effect without the submit button, so just switching on or off triggers the action?

    #48911
    PeterPeter
    Moderator

    Hello,

    Thanks for reaching out.

    When editing the View template, you can switch to the User tab and get the user field value, screenshot https://imgur.com/Vrrqdgk. Then use it in an if condition statement. For example:

    {% if ( user.switch_field_id ) %}
        do something
    {% else %}
        do other thing
    {% endif %}
    
    #48916
    EddyPiVEddyPiV
    Participant

    Peter, that's not what I want.

    To illustrate this image: https://drive.google.com/file/d/1z-Leoi2ysHyBy6Ek1r7KldYSSp0Qs7UN/view?usp=sharing

    I want to toggle, with immediate effect on the images shown. I don't want to submit.
    How can I do that?

    (It's just that the documentation says that it's saved in the database. So I added it as a user meta field. But I actually just need the toggle, switch on / off)

    #48923
    PeterPeter
    Moderator

    Hello,

    If you want to create a toggle button and show/hide some elements immediately, you can create some JavaScript code to do so. Here is an example https://www.w3schools.com/howto/howto_js_toggle_hide_show.asp

    Note: supporting the customization code is beyond our scope of support. If you are not able to complete the task, you can contact an expert developer to help you.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.