Extra fields not stored :( #1

Open
silverstripesk opened this Issue Jan 30, 2013 · 2 comments

Projects

None yet

2 participants

@silverstripesk

Hi Andreas,

storing extra fields doesn't work (with autosave on or off).

Look at my code:

class Billboard extends DataObject {

    static $db = array (
        'Cislo' => 'Varchar(127)',
        'Popis' => 'Text'
    );

    static $has_one = array(
        'Foto' => 'Image'
    );

    static $many_many = array (
        'Objednavky' => 'Objednavka',
    );

    static $many_many_extraFields = array(
    'Objednavky' => array(
        'StartDate' => 'Varchar',
        'EndDate' => 'Varchar'
    ),
    );

    static $searchable_fields = array(
        "Cislo"
    );

    static $summary_fields = array(
        'Cislo'
   );

    static $description = 'Zoznam billboardov';

    function getCMSFields() {

        $fields = parent::getCMSFields();

        if ($this->ID) {
            // add my custom formfield for subprojects
            $config = GridFieldConfig_RelationEditor::create();
            $config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array('Cislo'))->setResultsFormat('$Cislo');
            $gridField = new GridField("Objednavky", "Objednavky", $this->Objednavky(), $config);
            $fields->addFieldToTab("Root.Objednavky", $gridField);
            $component = new GridFieldEditableManyManyExtraColumns();
            $component->setSaveAutomatically(false);
            $fields->dataFieldByName('Objednavky')->getConfig()->addComponent($component, 'GridFieldEditButton');
            //$fields->addFieldToTab("Root.Extra", new TextField('ManyMany[StartDate]', 'Start'));
        } else {
            $fields->addFieldToTab("Root.Objednavky", new LiteralField("objnote","Objednavku pridáte po prvom uložení"));
        }

        return $fields; 
    }

}

and

class Objednavka extends DataObject {

    static $db = array (
        'Cislo' => 'Varchar(127)',
        'Popis' => 'Text'
    );

    static $has_one = array(
        'Zakaznik' => 'Zakaznik'
    );

    static $belongs_many_many = array (
        'Billboardy' => 'Billboard',
    );

    static $searchable_fields = array(
        "Cislo"
    );

    static $summary_fields = array(
        'Cislo'
   );

    function getCMSFields() {

        $fields = parent::getCMSFields();

        if ($this->ID) {
            // add my custom formfield for subprojects
            $config = GridFieldConfig_RelationEditor::create();
              $config->getComponentByType('GridFieldAddExistingAutocompleter')->setSearchFields(array('Cislo'))->setResultsFormat('$Cislo');
            $gridField = new GridField("Billboardy", "Billboardy", $this->Billboardy(), $config);
            $fields->addFieldToTab("Root.Billboardy", $gridField);
            $component = new GridFieldEditableManyManyExtraColumns();
            $component->setSaveAutomatically(false);
            $fields->dataFieldByName('Billboardy')->getConfig()->addComponent($component, 'GridFieldEditButton');
        } else {
            $fields->addFieldToTab("Root.Billboardy", new LiteralField("billnote","Billboardy pridáte po prvom uložení"));
        }

        return $fields; 
    }

 }

Any idea what is wrong? Im using SS 3.0.3.

Best regards

Pali

I actually have the same problem.
It also takes a LONG time to load.

I'm using MultiEnum for my extraField.

I found a fix. I'll submit a pull request for it soon.
If I forget, ping me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment