Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » JavaScript in the DOM popup

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 611 Views
  • Stef87
    Avatar
    Community Member
    66 Posts

    JavaScript in the DOM popup Link to this post

    Hi

    I am using 2.4.7 and want to add some javascript to the DOM popup. Basically what I want to happen is that when a certain value in a dropdown box is selected, another field appears (a textfield in this case).

    I tried this tutorial but had absolutely no success.

    I would be over the moon if someone could give me a hint about it. It is driving me crazy.

    Thanks

    Edit

    My attempts have been as unsuccessful as when I posted this but here is my code anyway.

    (function($) {
    $(document).ready(function(){
    var dropDown = $('#DataObjectManager_Popup_DetailForm_Status');
    var reason = $('#DataObjectManager_Popup_DetailForm_Reason');

    if(dropDown.val() == 'rejected' || 'Rejected'){
    reason.show();
    }
    else{
    reason.hide();
    };

        dropDown.change(function (e) {
        if(dropDown.val() == 'rejected' || 'Rejected'){   
           reason.show();
    alert(dropDown.val())
        }
        else{
           reason.hide();
        }
    })
    });
    })(jQuery);

    The reason textfield disappears as it is supposed to when I hit save but not when the dropdown is changed.

  • Stef87
    Avatar
    Community Member
    66 Posts

    Re: JavaScript in the DOM popup Link to this post

    11 days and 143 views later nobody has any advice?

    From my investigations it turns out that the Javascript is being called ok but the change part is not being applied. I'm stumped as to why not?

  • UncleCheese
    Avatar
    4085 Posts

    Re: JavaScript in the DOM popup Link to this post

    Check your script.

    if(dropDown.val() == 'rejected' || 'Rejected'){
    reason.show();
    }

    ^^ This always returns true, Because "Rejected" is a string with > 0 length, it is always evaluated as true.

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • Stef87
    Avatar
    Community Member
    66 Posts

    Re: JavaScript in the DOM popup Link to this post

    Thank you so much. I can't believe I was stuck on something so simple.

    611 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.