Execute javascript when editing an event. - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Execute javascript when editing an event.

  • Execute javascript when editing an event.
  • 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?




  • 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)
    function formCreatedHandler(sender, args)
        var detailFormView = sender,
        fieldControlIds = detailFormView._fieldControlIds,
        for (var i = 0, length = fieldControlIds.length; i < length; i++)
            var control = $find(fieldControlIds[i]);
            if (control)
                switch (control._fieldName)
                    case "CheckboxFieldName":
                            $(control._element).on('change', function (element)
                                if (element.target.checked)
                    case "TextBoxFieldName":
                            textBox = $(control._element);

    Velizar Bishurov
    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
  • 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?


    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?