Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

JavaScript in the DOM popup


Reply


4 Posts   774 Views

Avatar
Stef87

Community Member, 66 Posts

5 October 2012 at 3:19am

Edited: 15/10/2012 11:22pm

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 [url=http://www.ssbits.com/snippets/2011/inserting-javascript-into-a-dom-popup/]tutorial[/url] 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.

Avatar
Stef87

Community Member, 66 Posts

15 October 2012 at 11:22pm

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?

Avatar
UncleCheese

4085 Posts

16 October 2012 at 3:50pm

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

Avatar
Stef87

Community Member, 66 Posts

16 October 2012 at 9:00pm

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