Results 1 to 5 of 5

Thread: Conditional palette for child table based on parent table

  1. #1
    User
    Join Date
    04-10-11.
    Posts
    162

    Default Conditional palette for child table based on parent table

    Hi,

    I'm setting up a DCA that has a parent and child table, similar to how tl_news_archive and tl_news are set up. Is it possible to change the palette of records in the child table based on a select box in the parent table?

    For example I could have a select option on the parent record 'type_one' or 'type_two'. Depending on which of these was selected it would change the fields for any child records.

    Cheers,
    Jamie

  2. #2

    Default

    HI there,
    Just a rough idea, can't you use 'save_callback' on the field 'type_one' and make the field 'type_one's eval submitOnChange to true. So in the 'save_callback' function you may be able to change some variables!
    regards
    OM MANI PEME HUNG! how many has to die for freedom and dignity. Save this world

  3. #3
    User
    Join Date
    04-10-11.
    Posts
    162

    Default

    Thanks for the reply, this is similar to what I've done so far but I think you've slightly misunderstood what I'm trying to do.

    Just be clear in my child table I have 3 different palettes, I'm trying to load the palette which goes with the selection in the parent record.

    In the child table:

    Code:
    $GLOBALS['TL_DCA']['tl_child_table']['palettes'] => array
    (
            '__selector__' => array('category'),
            'default'      => 'category,published',       
            'cat_a' => 'category,field_one,field_two,published',   // These fields only apply to cat_a     
            'cat_b' => 'category,field_three,field_four,published', // These fields only apply to cat_b
    )
    In the parent table I have the category select field:

    Code:
    $GLOBALS['TL_DCA']['tl_parent_table']['fields']['category'] => array
    (
    	    'label'              => &$GLOBALS['TL_LANG']['tl_parent_table']['category'],
    	    'inputType'       => 'select',
                'options'           => array('cat_a' => 'Category A','cat_b' => 'Category B'),         
    	    'eval'               => array('mandatory'=>true, 'includeBlankOption'=>true)
    ),
    If a record in the parent table has it's category set to 'Category A', all of it's child records should only contain fields relevant to Category A (using the palette 'cat_a').

    In the child record I have a 'category' field which is disabled, this can't be changed from the child. I'm trying to use it as a selector using a load_callback. So when the child record loads 'im using the load_callback to get the parent's category and set the child's category to match. I was hoping this would update the palette of the child category, but it doesn't because the DCA has already been loaded. So the child has the correct category set, but the wrong palette to go with it. Some how I need to force Contao to switch the palette, this is where I'm stuck.

    Hopefully that makes sense!

  4. #4

    Default

    Please look into this very basic test module http://tinyurl.com/oqma6fl. may be it is some what you are looking for.
    OM MANI PEME HUNG! how many has to die for freedom and dignity. Save this world

  5. #5
    New user qzminski's Avatar
    Join Date
    01-08-13.
    Location
    Poland
    Posts
    24

    Default

    You should probably use the onload_callback and switch palettes from there.
    Contao ambassador
    Codefog - Contao web development

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •