CRED Multi checkbox frontend (Javascript , jQuery) validation

I have added a Types multicheckboxes field and want to add two custom validations to this field:
–The first one is to make the field required
–The second one is to force the client to select maximum two checkboxes

jQuery(document).ready(function() {
\This adds the validation method to our API so that CRED can recognize it
    jQuery.validator.addMethod("maxselections", function(value, element, param) {
                                var element_name = jQuery(element).attr('name');
                                return (jQuery('input[name="' + element_name + '"]:checked').length !=0 &&jQuery('input[name="' + element_name + '"]:checked').length <= param[1]);
                              });
\This adds the validations methods as attributes on the element itself.                               
    jQuery('input[name="wpcf-postscheckboxesfield[]"]').attr('data-wpt-validate', '{}')
        .data('wpt-validate', {
          maxselections: {
            args: {
              1: 2
            },
            message: 'You have to choose at least 1, maximum two items'
          }
    }); 
     
});

Validations on WP native fields in a CRED User form

Problem:
Validation and Required field option should work at once in CRED User form for native WP Fields (e.g. Last Name), same as builtin CRED validation style.

Solution:
1. Add this code in your theme’s or child theme’s functions.php file:

add_filter('cred_filter_field_before_add_to_form', 'required_fields_func', 10, 2);
function required_fields_func($field, $computed_values){
    if(in_array($field['id'], array('last_name', 'adresse'))){
        $field['data']['validate']['required'] = array ( 
            'active' => 1, 
            'value' => 1, 
            'message' => 'This field is required.'
        ) ;
    }
    return $field;
}

— Make sure to replace ‘last_name’, ‘adresse’ with your field slugs on line #3
— You can modify the message text as needed in above code on line #7.

2. OR If you want to have JS validation, you can use this (modification will be needed):
https://wp-types.com/forums/topic/cred-user-field-not-required/#post-567100

Related Ticket:
https://wp-types.com/forums/topic/cred-user-field-not-required/

RESET button for a Select Field only, in a CRED form

How to add Reset/Clear button for a Select Field only, in a CRED form?

1. Add this JS code in your CRED form >> JS editor section:


jQuery(document).ready(function( $ ){
jQuery('#reset_select').on('click',function(e){
jQuery(this).parent('.form-group').find("option:selected").removeAttr("selected");
});
});

2. Then use the below code in your CRED form, Reset button for the field, please replace field=’status’ with your field name and post=’book’ with your Custom Post Type:


<div class="form-group">
<label>Field Name</label>
[cred_field field='status' post='book' value='' urlparam='' class='form-control' output='bootstrap']

<button type="button" id="reset_select" value="Reset">Reset</button>
</div>