Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remember selection (code inside) #23

Open
MordiSacks opened this issue Dec 1, 2016 · 4 comments
Open

Remember selection (code inside) #23

MordiSacks opened this issue Dec 1, 2016 · 4 comments

Comments

@MordiSacks
Copy link

MordiSacks commented Dec 1, 2016

Hi,
I wrote a few lines of code, that rechecks selected items

Add the code in init.php after line 188 (search.$response.html(data);)

                            search.$response.find('input').each(function (k, v) {
                                if (search.$idInput.val().split(',').indexOf(v.value) >= 0) {
                                    jQuery(v).prop('checked', true);
                                }
                            });
@MordiSacks
Copy link
Author

updated comment, it is line 188, not 199

@aposidelov
Copy link

aposidelov commented Jul 30, 2018

For multiple selection: An id of each element must be trimmed otherwise only first checkbox will be selected:


let postIds = $.map(search.$idInput.val().split(","), $.trim);						search.$response.find('input').each(function ( k, v ) {					
if ( postIds.indexOf( v.value ) >= 0 ) {              	
  $(v).prop('checked', true);
}
});

@slaFFik
Copy link
Member

slaFFik commented Jan 20, 2019

@jtsternberg
I think this should be in CMB2-Post-Search-field plugin core.

@slaFFik
Copy link
Member

slaFFik commented Jan 20, 2019

The only issue so far: by default WP loads only 50 items in the list. So if you have more and the one selected is beyond those 50 default selected - they won't be display and selected (and when you click Submit - ignored).
We need to alter this behavior, so at the top of the list we will always load the selected items, and after that - those that are left. We will need to use pre_get_posts, as you have examples here: #21 (comment) - for post statuses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants