Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 3.0.2 (2026-10-08)

### 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_<target>_Holder`.
It now looks up `<form id>_<target>_Holder` in the icon's own form first (#3).

## 3.0.1 (2026-09-25)

### Licence
Expand Down
11 changes: 11 additions & 0 deletions client/dist/js/InlineInfoField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<form id>_<field name>_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"]');
Expand Down
12 changes: 12 additions & 0 deletions tests/browser/fixtures/IiBPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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();
Expand All @@ -47,6 +54,11 @@ public function getCMSFields()
);
$fields->push(InlineInfoField::create('Title', 'Keep titles <em>short</em>: 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;
}
Expand Down
40 changes: 40 additions & 0 deletions tests/browser/fixtures/IiBRecord.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Restruct\IiBrowser;

use Restruct\InfoField\InlineInfoField;
use SilverStripe\ORM\DataObject;

/**
* BROWSER-TEST FIXTURE ONLY - a record edited in a GridField detail form (IiBPage's "Records" tab),
* whose form is Form_ItemEditForm rather than the page editor's Form_EditForm (#3). An
* InlineInfoField is aimed at Title, and a Sub_Title field sits before Title: its holder id
* (..._Sub_Title_Holder) also ends in "_Title_Holder", so a suffix lookup would pick the wrong label.
*
* Never loaded by a real install (tests/browser/ carries a _manifest_exclude marker).
*/
class IiBRecord extends DataObject
{
# Short table names: no namespaced defaults, MySQL caps table names at 64 characters.
private static $table_name = 'IiBRecord';

private static $db = [
'Sub_Title' => '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 <em>title</em>.'));

return $fields;
}
}
16 changes: 14 additions & 2 deletions tests/browser/fixtures/IiBResetAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
}
}
24 changes: 24 additions & 0 deletions tests/browser/specs/fields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_<name>_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');
});
Loading