Jump to content

Title field: Prevent drop down of history when creating new page in admin


ottogal
 Share

Recommended Posts

Hi all,when an editor in the admin adds a new page and clicks the title input field, a drop down list would open to offer the formerly used titles. How can I prevent this?
(It seems to confuse my editors somehow.)
Thank you.

Link to comment
Share on other sites

You can disable autocomplete on input elements with the autocomplete attribute. You can modify built-in forms through hooks by looking up which Process module is creating the form and then hooking after it's buildForm method. In this case, it's ProcessPageAdd. This hook sets autocomplete="off" on both the title and the name input fields:

// site/init.php
wire()->addHookAfter('ProcessPageAdd::buildForm', function (HookEvent $e) {
    $form = $e->return;
    // disable autocomplete for the title field
    $title = $form->getChildByName('title');
    $title->attr('autocomplete', 'off');
    // disable autocomplete for the name field
    $pwPageName = $form->getChildByName('_pw_page_name');
    $pwPageName->attr('autocomplete', 'off');
});

 

  • Like 7
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

Ok, it worked ... till the moment when I (as Superuser) wanted to add a new User.
I got the "Fatal Error: Call to a member function attr() on null" in this line of the hook:

$title->attr('autocomplete', 'off');

As a workaround I replaced it with

if ($title) {
	$title->attr('autocomplete', 'off');
}; 

That helped - but I feel unsecure if there's something bad still left.

Obviously it's just because the user template doesn't have a title field...

  • Like 2
Link to comment
Share on other sites

16 hours ago, ottogal said:

Ok, it worked ... till the moment when I (as Superuser) wanted to add a new User.
I got the "Fatal Error: Call to a member function attr() on null" in this line of the hook:


$title->attr('autocomplete', 'off');

As a workaround I replaced it with


if ($title) {
	$title->attr('autocomplete', 'off');
}; 

That helped - but I feel unsecure if there's something bad still left.

Obviously it's just because the user template doesn't have a title field...

Yeah makes sense, checking if the field exists is sensible ? Should work fine. Maybe add the same check for the name field as well? If the template is set to generate the name automatically, the field may be missing as well (I think it skips this step entirely then, but it's an additional safeguard that won't hurt anyone). If you're paranoid you could use a whitelist of templates to apply the hook to as well, to make sure it will never have unintended consequences ...

  • Like 1
Link to comment
Share on other sites

15 hours ago, MoritzLost said:

Maybe add the same check for the name field as well? If the template is set to generate the name automatically, the field may be missing as well (I think it skips this step entirely then, but it's an additional safeguard that won't hurt anyone).

Good points - I did it.

Danke @MoritzLost !

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...