From acc926ab7c96155e3979f5cb432996d9a02fb705 Mon Sep 17 00:00:00 2001 From: micschk Date: Thu, 8 Oct 2026 13:19:23 +0200 Subject: [PATCH 1/2] FIX inline icon not moved into its label in GridField detail forms (#3) --- CHANGELOG.md | 8 +++++ client/dist/js/InlineInfoField.js | 11 +++++++ tests/browser/fixtures/IiBPage.php | 12 +++++++ tests/browser/fixtures/IiBRecord.php | 40 ++++++++++++++++++++++++ tests/browser/fixtures/IiBResetAdmin.php | 16 ++++++++-- tests/browser/specs/fields.spec.ts | 24 ++++++++++++++ 6 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 tests/browser/fixtures/IiBRecord.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7adfc3c..e4000a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 3.0.2 (unreleased) + +### Fixed + +- `InlineInfoField`'s icon was not moved next to its target's label in a GridField detail form, or + any form other than the page editor: the script only looked for `Form_EditForm__Holder`. + It now looks up `
__Holder` in the icon's own form first (#3). + ## 3.0.1 (2026-09-25) ### Licence diff --git a/client/dist/js/InlineInfoField.js b/client/dist/js/InlineInfoField.js index 68b97ba..c27e7da 100755 --- a/client/dist/js/InlineInfoField.js +++ b/client/dist/js/InlineInfoField.js @@ -10,6 +10,17 @@ var $label_el = $('#'+$(this).attr('data-target')); var $label_el = $('#Form_EditForm_'+ $(this).attr('data-target') +'_Holder'); + // Any form, not just the page editor (#3): a holder id is "__Holder" + // (FormTemplateHelper), and a GridField detail form is Form_ItemEditForm. Build the exact + // id from the span's own form rather than a suffix match: "_Title_Holder" would also match + // a "Sub_Title" field. getElementById, so a field name needs no selector escaping. + var $form = $(this).closest('form'); + if($form.length && $form.attr('id')){ + var $in_form = $(document.getElementById($form.attr('id') + '_' + $(this).attr('data-target') + '_Holder')); + if($in_form.length){ + $label_el = $in_form; + } + } if(!$label_el.length){ $label_el = $('[id$="Form_EditForm_'+$(this).attr('data-target')+'_Holder"]'); diff --git a/tests/browser/fixtures/IiBPage.php b/tests/browser/fixtures/IiBPage.php index f0d1cb2..8c85e23 100644 --- a/tests/browser/fixtures/IiBPage.php +++ b/tests/browser/fixtures/IiBPage.php @@ -5,6 +5,8 @@ use Restruct\InfoField\InfoField; use Restruct\InfoField\InlineInfoField; use SilverStripe\CMS\Model\SiteTree; +use SilverStripe\Forms\GridField\GridField; +use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; use SilverStripe\ORM\FieldType\DBField; /** @@ -23,6 +25,11 @@ class IiBPage extends SiteTree private static $singular_name = 'Info browser page'; + # Edited in a GridField detail form (#3): see IiBRecord. + private static $has_many = [ + 'Records' => IiBRecord::class, + ]; + public function getCMSFields() { $fields = parent::getCMSFields(); @@ -47,6 +54,11 @@ public function getCMSFields() ); $fields->push(InlineInfoField::create('Title', 'Keep titles short: they are also used in the menu.')); $fields->addFieldToTab('Root.Main', InlineInfoField::create('MenuTitle', 'Shown in the navigation.')); + # On its own tab, so the Main tab the other specs read is unchanged. + $fields->addFieldToTab( + 'Root.Records', + GridField::create('Records', 'Records', $this->Records(), GridFieldConfig_RecordEditor::create()) + ); return $fields; } diff --git a/tests/browser/fixtures/IiBRecord.php b/tests/browser/fixtures/IiBRecord.php new file mode 100644 index 0000000..8179a2f --- /dev/null +++ b/tests/browser/fixtures/IiBRecord.php @@ -0,0 +1,40 @@ + 'Varchar', + 'Title' => 'Varchar', + ]; + + private static $has_one = [ + 'Page' => IiBPage::class, + ]; + + public function getCMSFields() + { + $fields = parent::getCMSFields(); + $fields->removeByName('PageID'); + # Decoy first, so a suffix match on "_Title_Holder" would find it before Title. + $fields->changeFieldOrder(['Sub_Title', 'Title']); + $fields->push(InlineInfoField::create('Title', 'The record title.')); + + return $fields; + } +} diff --git a/tests/browser/fixtures/IiBResetAdmin.php b/tests/browser/fixtures/IiBResetAdmin.php index 1646db4..d2a3006 100644 --- a/tests/browser/fixtures/IiBResetAdmin.php +++ b/tests/browser/fixtures/IiBResetAdmin.php @@ -8,7 +8,8 @@ /** * BROWSER-TEST FIXTURE ONLY - gives a spec a page to open: GET /admin/iib-reset/reseed?title=... - * answers {"id": the IiBPage ID} (an existing page of that title is reused). + * answers {"id": the IiBPage ID} (an existing page of that title is reused); with &record=1 also + * "recordId", an IiBRecord on that page. * * A LeftAndMain because the admin routes those by url_segment with no YAML (the fixtures are copied * into app/src/). LeftAndMain's own access check applies, so only the logged-in admin can call it. @@ -33,8 +34,19 @@ public function reseed(HTTPRequest $request): HTTPResponse $page = IiBPage::create(['Title' => $title]); $page->write(); } + $data = ['id' => $page->ID]; + # ?record=1 also gives the page one IiBRecord, for the GridField detail form spec (#3). + if ($request->getVar('record')) { + $record = $page->Records()->first(); + if (!$record) { + $record = IiBRecord::create(['Title' => 'A record', 'Sub_Title' => 'Decoy']); + $record->PageID = $page->ID; + $record->write(); + } + $data['recordId'] = $record->ID; + } - return HTTPResponse::create(json_encode(['id' => $page->ID])) + return HTTPResponse::create(json_encode($data)) ->addHeader('Content-Type', 'application/json'); } } diff --git a/tests/browser/specs/fields.spec.ts b/tests/browser/specs/fields.spec.ts index b69e179..1b07611 100644 --- a/tests/browser/specs/fields.spec.ts +++ b/tests/browser/specs/fields.spec.ts @@ -93,3 +93,27 @@ test.describe('on a touch device', () => { expect(await isDisplayed(info.locator('> span'))).toBe(false); }); }); + +test('in a GridField detail form, the icon is moved into its target\'s label too (#3)', async ({ page }) => { + // The detail form is Form_ItemEditForm, not the page editor's Form_EditForm, so the field holders + // are Form_ItemEditForm__Holder. + const response = await page.request.get('/admin/iib-reset/reseed', { params: { title: 'Info fields records', record: '1' } }); + expect(response.status()).toBe(200); + const { id, recordId } = await response.json(); + await page.goto(`/admin/pages/edit/EditForm/${id}/field/Records/item/${recordId}/edit`); + const form = page.locator('form#Form_ItemEditForm'); + await expect(form.locator('input[name="Title"]')).toBeVisible(); + + const label = form.locator('#Form_ItemEditForm_Title_Holder label').first(); + await expect(label.locator('span.inline-info[data-target="Title"]')).toHaveCount(1); + await expect(label).toHaveClass(/\bhas-inline-infofield\b/); + // Not into Sub_Title, whose holder id also ends in "_Title_Holder". + await expect(form.locator('#Form_ItemEditForm_Sub_Title_Holder span.inline-info')).toHaveCount(0); + await expect(form.locator('span.inline-info')).toHaveCount(1); + + // And it still works there: hover shows the text. + const info = inlineInfo(form, 'Title'); + await info.hover(); + await expect(info).toHaveClass(/\bshow\b/); + await expect(info.locator('> span em')).toHaveText('title'); +}); From 69f80349742be7a3c44af599591bbd4d6ef7caa8 Mon Sep 17 00:00:00 2001 From: micschk Date: Thu, 8 Oct 2026 13:20:28 +0200 Subject: [PATCH 2/2] DOC Date the 3.0.2 changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4000a1..0d0a27b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 3.0.2 (unreleased) +## 3.0.2 (2026-10-08) ### Fixed