Skip Navigation

[Resolved] Bootstrap radio buttons with Ajax

This thread is resolved. Here is a description of the problem and solution.

Problem:
Bootstrap radio buttons with Ajax

Solution:
When you visit view's "Search and Pagination" section's JS box - you will see a button "Frontend Events". When you click it it will allow you to choose ajax callback events.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/bootstrap-radio-buttons-with-ajax/#post-1205315

Relevant Documentation:

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by katjaL 5 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1205099

I want to show Ajax radio button filtered search as Bootstrap buttons and active button should look a bit different. (Radio buttons are so 90's somehow, don't you think? That's why I wonder a little why it is so hard to show the buttons more modern way.)

Now I found this thread concerning CRED: https://toolset.com/forums/topic/bootstrap-radio-buttons/ and I've adjusted the code to my view with filtered search.

I'm almost there, but not quite 🙂 I need to add class .active to the chosen button and now when I choose a value it filters ok, and adds the .active class after "submit" ("Full page refresh when visitors click on the search button with input values auto-updating"), but not with Ajax ("AJAX results update when visitors change any filter values") .

At the moment I have this css:

.bootstrap-radio div {
font-size:30px;padding:0 15px 0 0px;margin-right:10px;
display:inline-block;background-color: #17984b;color:#fff;
border-radius:4px;
border:1px solid #fff;
cursor:pointer;
list-style:none;
}
.bootstrap-radio div input {display:none;}
.radio.active {background-color:#e77a6b;}

And this js

jQuery(document).ready(function( $ ){
$('.bootstrap-radio').find('input:checked').parents('div').addClass("active");
$('.bootstrap-radio').find('div').on('click',function(){
$('.bootstrap-radio').find('div').removeClass('active');
$(this).addClass('active');
});
});

#1205315

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

When you visit view's "Search and Pagination" section's JS box - you will see a button "Frontend Events". When you click it it will allow you to choose ajax callback events.

Refer this image:
=> hidden link

For example:

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
    /**
    * data.view_unique_id (string) The View unique ID hash
    * data.layout (object) The jQuery object for the View layout wrapper
    */
        
jQuery('.bootstrap-radio').find('input:checked').parents('div').addClass("active");
jQuery('.bootstrap-radio').find('div').on('click',function(){
jQuery('.bootstrap-radio').find('div').removeClass('active');
jQuery(this).addClass('active');
       
});

What if you try to adjust the JS code you shared within this event and check if that help you to resolve your issue.

#1205327

My issue is resolved now. Thank you! For the reference the final js is this:

jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {
$('.bootstrap-radio').find('input:checked').parents('div').addClass("active");
$('.bootstrap-radio').find('div').on('click',function(){
$('.bootstrap-radio').find('div').removeClass('active');
$(this).addClass('active');
});
});

jQuery(document).ready(function( $ ){
$('.bootstrap-radio').find('input:checked').parents('div').addClass("active");
$('.bootstrap-radio').find('div').on('click',function(){
$('.bootstrap-radio').find('div').removeClass('active');
$(this).addClass('active');
});
});