Skip Navigation

[Resolved] Split: Only 1 instead of 2 fields may be filled in – set cred field required dynamically using javascript/jquery

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 1 reply, has 2 voices.

Last updated by Minesh 1 year, 2 months ago.

Assisted by: Minesh.

Author
Posts
#2643101

Awesome!
Thank you!

Is it also possible to make the field REQUIRED whit this script?

#2643653

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I've adjusted the code added to your form's JS editor as given under:

jQuery(document).ready(function( $ ) {

    id = jQuery('[name="wpcf-afbeelding1"]').attr('id');
    $("#"+id).attr('required', true);
  
    
  $('input[type=radio][name="wpcf-kies-hoofdafbeelding-video"]').change(function() {
    if (this.value == 1) {
  
      id = jQuery('[name="wpcf-afbeelding1"]').attr('id');
    $("#"+id).attr('required', true);
  
      
      id = jQuery('[name="wpcf-hoofd-video"]').attr('id');
     jQuery( "#"+id ).removeAttr("required");
      
      
      
     	 $("[name='wpcf-afbeelding1']").removeAttr('disabled');  
      	 $("[name='wpcf-hoofd-video']").attr('disabled', 'disabled');
         $("[name='wpcf-hoofd-video']").val('');
      
            
      
    }else if (this.value == 2) {
      
      id = jQuery('[name="wpcf-hoofd-video"]').attr('id');
       $("#"+id).attr('required', true);
  
      
       id = jQuery('[name="wpcf-afbeelding1"]').attr('id');
       jQuery( "#"+id ).removeAttr("required");
     

      
      
      $("[name='wpcf-afbeelding1']").attr('disabled', 'disabled');
      $("[name='wpcf-afbeelding1']").closest("div.js-wpt-field-items").find("span.js-wpt-credfile-delete").trigger("click");
      $("[name='wpcf-hoofd-video']").removeAttr('disabled');  
       // $("[name='wpcf-kies-hoofdafbeelding-video']").val('');
    }
});
  
	$('.js-wpt-repadd').click(function( e ) {

    	var length = $('input[type="file"]', $(this).closest('.js-wpt-field-items')).length;

    	if(length>=6) {

    		$(this).hide();

    		$('.wpt-repctl').last().hide();

    	}

    });
  

});

You can even validate the form using the Toolset form's hook:
=> https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_validate