Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database values in formfield attributes don't update correctly when saving. #2622

Closed
GuySartorelli opened this issue Dec 10, 2020 · 4 comments

Comments

@GuySartorelli
Copy link
Member

GuySartorelli commented Dec 10, 2020

Version

4.6.0

Problem

Attributes set on a field which take the database value do not show the correct value when saving a new value on the field. The value of the attribute will always be taken from the previous save, unless you refresh the whole page.

Steps to reproduce

  1. Implement an Extension class that adds a new field, and sets an attribute using the database value:
$db = [
    'SomeField' => 'Varchar(255)'
];

public function updateCMSFields(FieldList $fields)
{
    $dbValue = $this->owner->dbObject('SomeField')->getValue();
    $fields->addFieldToTab('Root.Main',
        TextField::create('SomeField')->setAttribute('data-db-value', $dbValue)
    );
}
  1. Apply the extension to Page (it's possible the above directly in Page will also exhibit this issue - I haven't checked)
  2. Create a new page. Check the field - the attribute is missing.
  3. Set a value on the field and save, then check the field again. The attribute is still be missing despite a value having been saved to the database.
  4. Set a different value on the field and save, then check the field again. The attribute has the value from step 4! It should have the value that you just saved.
  5. Refresh the page and check the field. The attribute now shows the correct value.
@lerni
Copy link
Contributor

lerni commented Dec 10, 2020

This may well be related to silverstripe/silverstripe-framework#9124

@emteknetnz
Copy link
Member

emteknetnz commented Jan 8, 2021

I tried replicating this in 4.7.x-dev as well as 4.6.0, though I was unable to replicate this issue. The data-db-value="myvalue" is updating as I would expect it to

Code used:

mysite.yml

---
Name: myproject
---
SilverStripe\Core\Manifest\ModuleManifest:
  project: app
Page:
  extensions:
    - PageExtension

PageExtension.php

<?php

use SilverStripe\ORM\DataExtension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;

class PageExtension extends DataExtension
{
    private static $db = [
        'SomeField' => 'Varchar(255)'
    ];

    public function updateCMSFields(FieldList $fields)
    {
        $dbValue = $this->owner->dbObject('SomeField')->getValue();
        $fields->addFieldToTab('Root.Main',
            TextField::create('SomeField')->setAttribute('data-db-value', $dbValue)
        );
    }
}

Is there any other details you can provide to help replicate this issue?

@dhensby
Copy link
Contributor

dhensby commented May 20, 2021

Closing as we can't replicate and no response from OP

@dhensby dhensby closed this as completed May 20, 2021
@GuySartorelli
Copy link
Member Author

Sorry, somehow missed this until now.
I haven't been able to reproduce it so I'm not sure what was causing it... this can stay closed.

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

No branches or pull requests

4 participants