Hello,
I have a css problem with a drop-down selection in a view filter.
When I turn on the 'Show only available options for each entry' setting my css is no longer affected. (see point 2 on capture) But everything works fine with the 'Always show all values for inputs' setting (see point 1 on capture).
How is it and how can I fix this Toolset bug?
Thanks in advance.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
But how and where is the CSS being added?
That doesn't look like vanilla CSS.
If you just add straight CSS to the page with style rules for the filters they will persist even after updating the filters.
If you are doing something else, such as using JavaScript to apply styles then that won't be the case, but I need to understand how you are applying the CSS to comment further.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
I would recommend adding your CSS as CSS, in which case the issue will not arise.
If you use JavaScript to apply the CSS the problem is that when you make changes to the select filters then the those filters within the DOM are replaced with updated filters, and your changes are evidently lost.
In such circumstances you need to re-run the JavaScript that applies the CSS, and you can trigger your code using the custom JavaScript events that Views provides for when certain actions have taken place, in this case the search form has been updated with new filter values.
So in the custom JS editor of the Search and Pagination section you will see a button "Frontend events" that can be used to insert some wrapper JS code that includes the required event (see screenshot).
That will insert the following:
jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {
/**
* data.view_unique_id (string) The View unique ID hash
* data.view_changed_form (object) The jQuery object for the View form after being updated
* data.view_changed_form_additional_forms_only (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-form-view] shortcode
* data.view_changed_form_additional_forms_full (object) The jQuery object containing additional forms from other instances of the same View inserted using the [wpv-view] shortcode
*/
});
You can use that to trigger your code to re-apply the CSS.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
I take it that it looks okay on the initial page load because however you are adding the CSS (I still can't tell from what you shared) it is added when the page loads.
When you have the setting to show all the options in the select filter, making changes to the filter doesn't replace the select element in the DOM.
When you have the setting to only show available options then whenever any change is made to any filter an ajax request is sent to the server which then sends back the updated filters, the current filters are deleted and replaced with the new filters.
So if you used JavaScript to make some changes to the filter elements directly, e.g. applying inline styles, then those will be lost because the select elements are removed from the DOM and new ones inserted. Which is why you would need to run the JS again to re-apply its changes to the new select elements.
What you've pasted above isn't CSS or JS, so I'm not really sure what you are doing. It looks like SASS or LESS, or maybe its a jQuery plugin, I can't tell.