ottogal Posted May 28, 2020 Share Posted May 28, 2020 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 More sharing options...
MoritzLost Posted May 28, 2020 Share Posted May 28, 2020 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'); }); 7 1 Link to comment Share on other sites More sharing options...
ottogal Posted May 29, 2020 Author Share Posted May 29, 2020 Thank you so much, @MoritzLost, that worked - and I've learned again something... 1 Link to comment Share on other sites More sharing options...
ottogal Posted June 7, 2020 Author Share Posted June 7, 2020 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... 2 Link to comment Share on other sites More sharing options...
MoritzLost Posted June 7, 2020 Share Posted June 7, 2020 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 ... 1 Link to comment Share on other sites More sharing options...
ottogal Posted June 8, 2020 Author Share Posted June 8, 2020 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 ! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now