Conditionally Show/Hide or Enable/Disable an option in a radio button list

Binod Paikaray asked on May 13, 2018 20:44

Hello,

I have a custom form control for uploading a file and a radio button field of Kentico with three options on my form.

Based on the uploaded file extension, I need to show/hide or enable/disable one of the option in the radio button list and for this I need your help. I tried with macro but couldn't find anything related to single option of radio button.

Thanks,

Binod Paikaray

Recent Answers


Brenden Kehren answered on May 13, 2018 21:39

This would be best handled with JavaScript. Doing this with server side code would mean you'd have to create a custom form control.

1 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on May 15, 2018 12:47 (last edited on May 15, 2018 12:48)

Thanks very much Brenden for your response!

Is there any way to get the uploaded file extension before saving the form and use same extension in some other field via macro?

Thanks,

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on May 15, 2018 14:55

I agree with Brenden, using Javascript you should be able to simply read the textbox of the Upload control (which depending on which one, should show the file path, including the file extension) and do a show/hide.

If you wanted to do it server side, I don’t believe there is anyway by default to grab that value using macros. If you wanted to do it, this is what you would have to do:

  1. Create or clone the Upload File form control
  2. Modify the “File Select” portion of that upload form control, to trigger when they select a file (there may already be a hook or event for this)
  3. Use the MacroContext.CurrentResolver.SetNamedSourceData(“TheUploadExtension”, TheUploadExtensionValue);
  4. Leverage that in your visible field (ex: {% TheUploadExtension == “pdf” %})

Hope that helps!

0 votesVote for this answer Mark as a Correct answer

Binod Paikaray answered on May 16, 2018 15:18 (last edited on May 16, 2018 16:38)

Thanks very much Trevor for your response!

May be my question is silly but just wanted to be more clear.

We have created a custom uploader inside which we are using Kentico's Direct Uploader itself (~\CMSModules\Content\Controls\Attachments\DocumentAttachments\DirectUploader.ascx) and the extra thing which we included in this is a preview option of the file.

After this, we have a document type called "File Attachment" in which one of the field is "File" to which the above mentioned custom form control is assigned.

Now we've recently added a radio button list in the document type itself from Kentico UI which has three options:

  1. Sidebar

  2. Embed

  3. Inline

Now, on the basis of selected file extension (before saving it to DB), we need to show/hide "Embed" option where I'm stuck. As per my understanding from various posts, we can assign the source to radio button list with some conditions as well using macro but before that I need to get the file extension.

And to do same with javascript, I'm confused to how get the new file upload event and the update file event (inside a grid in direct uploader) where I need to fetch the file extension and show/hide the "Embed" option in radio button list.

Waiting for your help now!

Thanks,

Binod Paikaray

0 votesVote for this answer Mark as a Correct answer

Trevor Fayas answered on May 17, 2018 02:22

Javascript will definitely be easier in this case. It still is possible to do it my way, where you add stuff to the current Macro Resolver, but it's a lot of work just to get that.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.