silverstripe-gridfield-betterbuttons icon indicating copy to clipboard operation
silverstripe-gridfield-betterbuttons copied to clipboard

'Add New' Button Interferes with GridFieldAddExistingAutoCompleter 'link existing on click of enter' key logic

Open HARVS1789UK opened this issue 9 years ago • 3 comments

Browser: Google Chrome (Version 49.0.2623.110 (64-bit)) SilverStripe: v3.1.18

The default behaviour of GridFieldAddExistingAutoCompleter is that once I have searched for an selected a related object to be added to my GridField, I can make the relationship/addition by either:

  • Clicking 'Link Existing'
  • Pressing 'Enter/Return' whilst still focussed in the link existing search field

I am finding that GridFieldBetterButtons is interfering with the second of those two options as hitting enter (whilst focused on anything on the page) triggers a click of the 'New Record' button.

I have had a quick look at the GridFieldBetterButtons JS but cannot see any on KeyUp, KeyDown or KeyPress listeners, so perhaps this is something to do with default browser behaviour (i.e. triggering a click of the first button or input with type="submit" it can find on the page, if any) however as that behaviour is not followed when GridFieldBetterButtons are not enabled, and there are no doubt some

screen shot 2016-04-10 at 13 09 31

HARVS1789UK avatar Apr 10 '16 12:04 HARVS1789UK

There's no reason I can see that the new button needs to be type=submit. I think all we'd have to do to resolve this issue is to change BetterButton_New to be a simple BetterButtonLink to $gridField->Link('item/new');

unclecheese avatar Apr 13 '16 22:04 unclecheese

@unclecheese that sounds like it may well solve the issue, I have had a look through the modules code base in an attempt to find where the individual utils are added into some kind of FieldList or similar, but I can't find that anywhere :-S

I was thinking about using a getBetterButtonsUtils() method on a per DataObject basis to replace the existing BetterButton_New with a BetterButtonLink but then I released I would not have any access ot the GridField object in that context and so would not be able to do $gridField->Link('item/new') for example, this solves the original issue of 'hitting enter anywhere on the page creates a new DO':

    public function getBetterButtonsUtils() {

        $utils = parent::getBetterButtonsUtils();

        $utils->replaceField(
            'action_doNew',
            BetterButtonLink::create('New Record', '/admin/orders/Order/EditForm/field/Order/item/new')
                ->addExtraClass("ss-ui-action-constructive")
                ->setAttribute('data-icon', 'add')
        );

        return $utils;

    }

However:

  1. That link is hardcoded and would only work when editing Order objects through my Order ModelAdmin extension
  2. Having to do this on a DataObject by DataObject basis would be pretty repetitive and annoying

Is there anyway that I could switch all BetterButton_New instances for BetterButtonLink 's at a config level, cleanly without hacking around with the module code itself? Alternatively is this a change you would be willing to make to the modules core code? I'd be happy to submit a pull request if you can point me in the right direction as to where the utils get defined and added in the first place?

Cheers,

HARVS1789UK

HARVS1789UK avatar Apr 21 '16 17:04 HARVS1789UK

Hi @unclecheese any thoughts on the above? I really want to prevent this issue in a current project as it's one of the last outstanding bugs/issues.

I am happy to do some of the work, but as above, I need pointing in the right direction.

HARVS1789UK avatar Jun 04 '16 15:06 HARVS1789UK