Skip Navigation

[Resolved] Set filter to required

This support ticket is created 6 years, 2 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.

Our next available supporter will start replying to tickets in about 1.09 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 14 replies, has 2 voices.

Last updated by Matthias Reichl 6 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1105557

Hi,

I´ve created for radio buttons / select filter for a view. How can I enable, that all these filters are required to be set before I can submit?

And a second question, which fits this topic also: is there any way to include a general option per filter, which says "I don´t know yet"? This general option should load all results from the selected filter and is similar to the default option "All".

Regards,

#1106409

Hello,

Yes, you are right, those two issues are related.

Q1) all these filters are required to be set before I can submit ...
There isn't such a feature within Views plugin, it needs custom JS codes, for example:
hidden link

So the best workaround is using the default option "All", see below Q2.

Q2) is there any way to include a general option per filter, which says "I don´t know yet"?
Yes, this is possible "Select" filter field, for example shortcode [wpv-control-post-taxonomy], attribute "default_label":
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-post-taxonomy
default_label (opt):
'default option text'
Add default option like All or Any on taxonomy select control.

#1106556

Hi,

thanks. Q2 is solved.

Regarding Q1:
- what form id should I use for this javascript? I´ve inserted the necessary scripts to my header.
- What is field: ID or is field the name:
$( "#myform" ).validate({
rules: {
field: {
required: true
}
}
});

Regards,

#1106564

You can try the CSS class name "wpv-filter-form" of search form, for example:

$( "form.wpv-filter-form" ) ...
#1107568

Thanks, can you please show me an example with the further section? What have I to use for "field"?
This is my filter:

<div class="form-group">
	<label>[wpml-string context="wpv-views"]Für welches Projekt suchen Sie?[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="schwerpunkt" type="radios" default_label="Ich weiß es noch nicht." url_param="wpv-schwerpunkt"]
</div>

  <div class="form-group">
	<label>[wpml-string context="wpv-views"]Für welche Formen interessieren Sie sich?[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="form" type="radios" default_label="Ich weiß es noch nicht." url_param="wpv-dachform"]
</div>
<div class="form-group">
	<label>[wpml-string context="wpv-views"]Für welches Objekt suchen Sie [/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="projektart" type="radios" default_label="" url_param="wpv-projektart"]
</div>
<div class="form-group">
	<label>[wpml-string context="wpv-views"]In welchem Bundesland liegt ihr?[/wpml-string]</label>
	[wpv-control-post-taxonomy taxonomy="bundesland" type="select" default_label="Liste aller Bundesländer" url_param="wpv-bundesland"]
</div>

I´ve tried the code, but it doesn´t work at all. The scripts are not compatible to each other:
Uncaught TypeError: Cannot read property 'addMethod' of undefined
Uncaught TypeError: Cannot read property 'setDefaults' of undefined
I´ve added these scripts to my header:
<script src="hidden link"></script>
<script src="hidden link"></script>
<script src="hidden link"></script>

Regards,

#1108089

Since it is custom codes problem, please provide a test site with the same problem, I need to test and debug it in a live website

#1108173

For the JS errors you mentioned in private message box, it is your custom PHP codes in your theme/functions.php:

//* Enqueue Toolset Required
add_action( 'wp_enqueue_scripts', 'toolset_required' );
function toolset_required() {
    wp_enqueue_script( 'j-validate', '<em><u>hidden link</u></em>', array(), 20151215 );
    wp_enqueue_script( 'j-validate', '<em><u>hidden link</u></em>', array(), 20151215 );
    wp_enqueue_script( 'j-add-validate', '<em><u>hidden link</u></em>', array(), 20151215 );
}

I have changed it to:

//* Enqueue Toolset Required
add_action( 'wp_enqueue_scripts', 'toolset_required' );
function toolset_required() {
    //wp_enqueue_script( 'j-validate', '<em><u>hidden link</u></em>', array(), 20151215 );
    wp_enqueue_script( 'j-validate', '<em><u>hidden link</u></em>', array('jquery'), 20151215 );
    wp_enqueue_script( 'j-add-validate', '<em><u>hidden link</u></em>', array('jquery'), 20151215 );
}

Your website has already loaded JS file "jquery.js?ver=1.12.4", you don't need to load anther one.

For the custom JS codes in view "Partnersuche", you can follow their document to setup your own custom JS codes:
hidden link
See the live example codes of radio field:
hidden link

#1108191

Hi,

thanks - the errors are gone.

I tried your example, but it doesn´t seem to work with toolset. The error label is displayed till I click on submit, then it is hidden, but I cannot submit anyway - nothing happens any more.

Regards,

#1109122

I am checking it in your website, will update here if there is anything found

#1109278

There might be some conflict issues with your CSS codes, I have done below modification in your website:
Edit the view "Partnersuche":
hidden link
1) in section "Search and Pagination", edit your CSS codes, comment out those CSS codes:

/** input[type="radio"] {
    opacity:0.01;
    z-index:1;
  	display:none; 
}**/

2) Modify the JS codes, disable "debug":

jQuery(document).ready(function($) {
    jQuery.validator.setDefaults({
    	//debug: true,
    	success: "valid"
	});
    $( 'form.wpv-filter-form' ).validate({
      rules: {
        'wpv-schwerpunkt': {
          required: true
        },
        'wpv-dachform': {
          required: true
        },
        'wpv-projektart': {
          required: true
        }
      }
    });
});

Please test again, check if it is fixed. and it is only a demo for your reference, you will need to customize your own CSS codes.

#1115059
Clipboard01.png

Hi,

thanks. Yes, it´s working now - partly. Have you got any idea, how I can translate "This field is required". Also it creates empty labels above the selected radio button, when I missed some field and tried to submit my query - see attached image.

At the search result page nothing is displayed. Finally when I hit the button "Planer suchen" again then the results are displayed. What could be wrong here, because that worked some time ago? Is this an incompatibility with the required JS?

Regards,

#1115472

For the new questions:
Q1) Have you got any idea, how I can translate "This field is required".

There isn't such feature within Toolset, I have searched it in google, found this thread:
https://stackoverflow.com/questions/39630386/translate-custom-jquery-validation-messages

For your reference

Q2) What could be wrong here, because that worked some time ago? Is this an incompatibility with the required JS?
there might be some CSS/JS compatibility problem in your website, I suggest you try to deactivate other plugins, switch to wordpress default theme, disable all other CSS/JS codes in the view, and test again.

if you still need assistance for the new questions, please create a new thread for it, that will help other users to find the answers.

#1115483

Hi,

thanks.

Q1 is resolved.
Q2: I will create a second ticket.
Q3: I think you haven´t mentioned my last question: Also it creates empty labels above the selected radio button, when I missed some field and tried to submit my query - see attached image. Have you any idea how to hide the empty label fields of the validator js?

Regards,

#1115544

Q3) The empty label is created by "jqueryvalidation", you can use CSS codes to hide the empty label, for example:


label.error:empty {
  display:none !important;
} 
#1115545

My issue is resolved now. Thank you!