Skip Navigation

[Resolved] Only 1 instead of 2 fields may be filled in

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 4 replies, has 2 voices.

Last updated by Minesh 1 year, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2642617
Schermafbeelding 2023-09-11 om 09.00.50.png

Tell us what you are trying to do?

I have built a POST Form, students can post a project.
At some point they may post an image OR YouTube link.
With conditional an image field is shown or a field to place the YouTube link.
Students may either fill in one field OR the other field.
But once they have placed the image, they can still click on the radio button of the YouTube link and place a link in that field.

How can I prevent that?

What is the link to your site?
hidden link

#2642691

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Thank you for sharing problem URL but it seems I will require admin access details to see the form.

Can you please share frontend user access details (if required) and admin access details so I can check how exactly you setup your form.

The current way is I think legit as user visit the form and chose the option to either upload image or add youtube link but lets say user chose the image and upload the image and save the form it will have image uploaded.

But in another case lets say user visit the form and chose the option to either upload image or add youtube link, in this case decide to upload image so user will select to upload image option and later he changes his mind not to upload image and go with youtube link. What you say about this?

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2642761

Minesh
Supporter

Languages: English (English )

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

I've added the following custom JS code to your form's JS editor inside the document.ready event:
=> hidden link

$('input[type=radio][name="wpcf-kies-hoofdafbeelding-video"]').change(function() {
    if (this.value == 1) {
     	 $("[name='wpcf-afbeelding1']").removeAttr('disabled');  
      	 $("[name='wpcf-hoofd-video']").attr('disabled', 'disabled');
         $("[name='wpcf-hoofd-video']").val('');
      
    }else if (this.value == 2) {
      $("[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');  
    }
})

What it does it it resets the value of your file and youtube video field when you change the selection. So there will be no value available when user select another field for another field.

This is the workaround you will have to use in your case.

#2643073

Awesome!
Thank you!

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

#2643103

Minesh
Supporter

Languages: English (English )

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

Glad to know that solution I shared help you to resolve the original issue you reported with this ticket.

As per our support policy, we entertain only one question per ticket. This will help other users searching on the forum as well as help us to write correct problem resolution summery.

I'll split the ticket with your new question. We will continue with the following new ticket.
=> https://toolset.com/forums/topic/split-only-1-instead-of-2-fields-may-be-filled-in-set-cred-field-required-dynamically-using-javascript-jquery/

You are welcome to mark this ticket resolved.