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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Manipulate AddPageOptionsForm in CMS


Go to End


3 Posts   992 Views

Avatar
bartvanirsel

Community Member, 96 Posts

19 March 2011 at 12:54am

Hi,

I'm looking into changing the default selected option in AddPageOptionsForm for creating new pages.

Is this posible to set in (php) code? I tried some JQuery but that didnt work out.

Behaviour.register({
    '#Form_EditForm' : {
        initialize : function() {
            this.observeMethod('PageLoaded', this.adminPageHandler);
            this.adminPageHandler();
        },
        adminPageHandler : function() {

            jQuery("#Form_AddPageOptionsForm_PageType option")
                .each(function() {
                    if (jQuery(this).val() == 'DefaultSelectedPage')
                    {
                        jQuery(this).attr('selected', true);

                    }
            });

        }
    }
});

Avatar
Carbon Crayon

Community Member, 598 Posts

30 March 2011 at 11:41pm

Hi Bart,

I think if you add this to your Page class it should do the trick:

static $default_child = 'DefaultPageClass';

Aram

Avatar
bartvanirsel

Community Member, 96 Posts

1 April 2011 at 10:10pm

Hi Aram,

Thanks, I'll try that out as well.

In the end i managed to do this by doing it with javascript (jQuery) ::required by LeftAndMain.
[[PageTypeToBeDefault]] is the default page.

Behaviour.register({
    '#Form_EditForm' : {
        initialize : function() {
            this.observeMethod('PageLoaded', this.adminPageHandler);
            this.adminPageHandler();
        },
        adminPageHandler : function() {

            jQuery("#Form_AddPageOptionsForm_PageType option")
                .each(function() {
                    if (jQuery(this).val() == '[[PageTypeToBeDefault]]')
                    {
                        jQuery(this).attr('selected', true);
                    }
            });

        }
    }
});

Bart