Execute javascript when editing an event.

Posted by Community Admin on 04-Aug-2018 17:15

Execute javascript when editing an event.

All Replies

Posted by Community Admin on 18-Apr-2016 00:00

Hello,

I'm working on the Events module and have two custom fields:

1. Checkbox (Type: Yes/No)

2. Textbox (Type: Short text)

My requirement is

  - when the checkbox value is Yes, the textbox field should be shown. 

  - when the checkbox value is No, the textbox field should be hidden. 

I'm thinking to use javascript to handle this but no idea to get started. Or is there a better way to accomplish this?

 

Thanks,

Brew

Posted by Community Admin on 21-Apr-2016 00:00

Hello Brew,

You can refer to the following blog post where the concept of extension scripts in Sitefinity is explained: http://www.sitefinity.com/blogs/vassil-vassilev-s-blog/vassil-vassilev's-posts/vassil-vassilevs-blog/2014/12/15/how-to-add-predefined-values-to-the-backend-create-view-of-dynamic-content-items

Once familiar with the concept here is an example extension script that would achieve your needs:

function OnDetailViewLoaded(sender, args)
    sender.add_formCreated(formCreatedHandler);
 
function formCreatedHandler(sender, args)
    var detailFormView = sender,
    fieldControlIds = detailFormView._fieldControlIds,
        textBox;
 
    for (var i = 0, length = fieldControlIds.length; i < length; i++)
        var control = $find(fieldControlIds[i]);
        if (control)
            switch (control._fieldName)
                case "CheckboxFieldName":
                    
                        $(control._element).unbind('change');
                        $(control._element).on('change', function (element)
                            if (element.target.checked)
                                textBox.show();
                             else
                                textBox.hide();
                            
                        );
 
                        break;
                    
                case "TextBoxFieldName":
                    
                        textBox = $(control._element);
                        break;
                    
            
        
    

Regards,
Velizar Bishurov
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 21-Apr-2016 00:00

Hi Velizar,

This works fine when adding a new one. How about editing? How do I retrieve the value for the checkbox so I can set the textbox visibility when loading a page?

Ex.

Add mode: the checkbox field is checked; the textbox field is hidden. (this works ok with your suggestion)

Edit Mode: How to know the value of checkbox here to set the textbox visibility?

Thanks,

Brew

This thread is closed