Jump to content

[SOLVED] Disable "add" button in Page Reference field


Recommended Posts

I am little stuck on option to hide dropdown button on page reference input.
I have child pages from page reference field linked and visible and they should not be addable from list of referenced pages.
I need only option to add new child pages from parent page but not to show dropdown of all not linked.
New child pages are every time unique so when they are added they are linked with parent
Is possible to disable or hide that dropdown "add" button ?

Thanks for any help...
 

Link to comment
Share on other sites

Hi,

there is something i do not understand...
when using the page reference field, once you've defined a parent page, the dropdown will show all its children but, the data returned to your template/frontend will only be the one(s) you've chosen, how will you choose those ones without seeing them in the dropdown backend wise?
if you choose the pageArray option and the texttags type of field, the reference field will act as a selectize like field, allowing you to chose, order and delete your chosen items frontend wise, only an array of this choice will be returned and not all the children of the parent page published or not...

hope it helps

have a nice day

Link to comment
Share on other sites

5 hours ago, virtualgadjo said:

Hi,

there is something i do not understand...
when using the page reference field, once you've defined a parent page, the dropdown will show all its children but, the data returned to your template/frontend will only be the one(s) you've chosen, how will you choose those ones without seeing them in the dropdown backend wise?
if you choose the pageArray option and the texttags type of field, the reference field will act as a selectize like field, allowing you to chose, order and delete your chosen items frontend wise, only an array of this choice will be returned and not all the children of the parent page published or not...

hope it helps

have a nice day

Hi.
I could explain. I am working on system for my customer who has contracts and in contracts are products items.
Parent page is contract and child pages are product items. Every product items is unique so when customer adds new product item it is not used in other contracts then current.
I had to import older data from MS Access tables and I used page reference field only for linking specific product items for parent contract page.
Customer is using PW admin for editing data since I do not want to create extra forms for same functions on frontend.
So now I have all in PW, but customer wants to hide that "add" button - mainly to disable dropdown, because is using only "new" button for adding only new child page.
For this reason I need to hide that dropdown. So result should be only "new" button visible and that "add" hidden...
If there is possible to have some permission or access rules setting to allow for some user in PW only to add new child page without dropdown of all current - it would be nice...
Do you understand now ?

Link to comment
Share on other sites

Posted (edited)

In fact I think your solution is to remove this page reference field, you don't need it because you are using a parent/child relationship that is already implemented by default in PW.

Edited by da²
Link to comment
Share on other sites

1 hour ago, Christophe said:

Hello Pavel,

In your page reference field, in the Input tab, is Allow new pages to be created from field? ... selected?

Which Input field type have you chosen?

Hi.
Yes it is selected and that function I want to let customer add new child pages.
Input field is Page/ListSelectMultiple.

Here is screenshot - site is my language (Czech as default)

image.png.6f2742dc87e2edef116ba6952b75aab2.png

As you could see there is selected and linked one item (child page) and that first button with dropdown is first one "Přidat" - in English it is "Add".
Second one is to create new "Vytvořit novou" - this I need to have visible...

I need to hide that first button with dropdown ("Přidat")

Or if it is possible to have same function with same design without need of dropdown selections ???

What do you think ?

Link to comment
Share on other sites

2 hours ago, da² said:

In fact I think your solution is to remove this page reference field, you don't need it because you are using a parent/child relationship that is already implemented by default in PW.

I need reference field to have in admin pages linked and editable data for customer...

Is possible to achieve same design of editing parent page with children (linked to it) other way ? 

Link to comment
Share on other sites

Posted (edited)

I don't understand what you need to do, can you give examples?

1 hour ago, PavelRadvan said:

Is possible to achieve same design of editing parent page with children (linked to it) other way ? 

Parent pages and children are always linked, you don't need a page reference field to link children to a parent. If you're doing only this, you can remove it.

What kind of page do you want to add with the page reference field? Do you have set the options on this field to filter the pages it allows?

EDIT: I didn't see this message. If the goal is only to create child pages, why not using the "Children" tab?

Edited by da²
Link to comment
Share on other sites

It is more complex...I have pages in PW which are contracts - for more info please look here where is all explained:
https://processwire.com/talk/topic/29959-link-page-with-multiple-pages-by-field-value-in-backend/

I completed import of data and linked tables (pages) with other data from pages by script.
So now parent pages are linked with children pages. Parent page has its template and children page also has its template.
I could use "children" tab, but part of contract page is not only children from one page, there are also other fields in template...
So I need just have in parent page template field with visible linked children pages and option to add only new pages and not to show dropdown - it is not for my need it is mainly for customer request.
Just to have only "create new" button and not accidentally show large dropdown by click on "add" button...
Is that more clear for you ?

 

Link to comment
Share on other sites

12 hours ago, da² said:

I don't understand what you need to do, can you give examples?

Parent pages and children are always linked, you don't need a page reference field to link children to a parent. If you're doing only this, you can remove it.

What kind of page do you want to add with the page reference field? Do you have set the options on this field to filter the pages it allows?

EDIT: I didn't see this message. If the goal is only to create child pages, why not using the "Children" tab?

I have to specify that I have page for contracts and it is linked to another page to its children (products items)  - so for this reason it is used page refernce field.
In system I am working on is about 1200 pages for one type of contract linked to about 5000 pages of product items and about 8000 pages for other type of contract linked to about 50000 pages of product items.
I hope this help to explain more the situation...

Link to comment
Share on other sites

Hi,
not sure i understand completely the whole story but, i may be wrong, it seems to me that you are using this page reference field to organize your backend structure when it's designed more to be sort a predefined $pages->find you'll retreive on the font end which as @da² says, is more the role of the family tab of the templates where you can define which template can have as children pages and what parent template can be the parent of a defined page/template

more, when defining those relations between template the add new button to the top right of the admin let you add a new page chosing its template and it will automatically added to its correct parent
the new button of each page will also automatically be added with the correct template

sorry if i've completely misunderstood your problem...

have a nice day

Link to comment
Share on other sites

3 hours ago, virtualgadjo said:

Hi,
not sure i understand completely the whole story but, i may be wrong, it seems to me that you are using this page reference field to organize your backend structure when it's designed more to be sort a predefined $pages->find you'll retreive on the font end which as @da² says, is more the role of the family tab of the templates where you can define which template can have as children pages and what parent template can be the parent of a defined page/template

more, when defining those relations between template the add new button to the top right of the admin let you add a new page chosing its template and it will automatically added to its correct parent
the new button of each page will also automatically be added with the correct template

sorry if i've completely misunderstood your problem...

have a nice day

Hi. This function you write is ok - I need to have already linked pages visible and option to add ONLY new to referenced page children which will be also linked.
I do not need to see list from dropdown, because every children is new and always unique and others are not used for new page.
Customer do not need to choose from previous created children pages of referenced page, because every new one is unique...
For this reason I need only to have visible list of already linked children pages from referenced page (already done by script from imported data) and to disable that "add" button with dropdown list.
Button "create new" is needed so this should be there ...
Customer is creating new data by link from frontend which starts function and hook and creates new page (with predefined major data) where is that page reference field I am talking about.
In this case there is no linked page and customer do not need to click and see other children pages to select (it is for him of not use) , but needs ONLY to add new, because every time it is new (no need of other items in referenced page children)
When customer is editing data (again in backend) then he needs to see previously selected linked children pages from referenced page and again do not need to have option to select from others...
He needs to change linked items or to create new.
Do you understand now ?

 

Link to comment
Share on other sites

To simply hide the Add button of the PageListSelectMultiple field for non-superusers or for all, you can use some custom JS.

Example:

JS in site/templates/scripts/admin-custom.js

// custom admin script

console.log("admin-custom.js loaded");

/**
 * Hides the "Add" button for the Inputfield Page List Select Multiple field with given fieldName.
 * This function is intended to restrict access to adding existing items for non-superuser roles.
 */
function hideAddButtonForInputfieldPagelistSelectMultiple(fieldName) {
  // Uncomment the following line to also hide for superusers
  // config object is globally available in the admin and contains user objecyt with roles array
  // if (config.user.roles.includes('superuser')) return;

  const wrapper = document.getElementById('wrap_Inputfield_' + fieldName);
  if (!wrapper) return;

  const start = wrapper.querySelector('a.PageListSelectActionToggleStart');

  if (start) {
    start.style.display = 'none';
  }
}

window.onload = function () {
  hideAddButtonForInputfieldPagelistSelectMultiple('my_pagelist_select_multiple'); // pass in your field name here
};

To load that script in site/templates/admin.php

...
// load site/templates/admin-custom.js
$config->scripts->add($config->urls->templates . 'scripts/admin-custom.js');

/** @var Config $config */
require($config->paths->core . "admin.php");

You could do this with custom CSS. But there you don't have the user role available.

EDIT: or you do it with CSS and load it depending on user role in admin.php ?

site/templates/admin.php

// load site/templates/admin-custom.css for non superusers
if(!$user->isSuperuser()) $config->styles->add($config->urls->templates . 'styles/admin-custom.css');
...

site/templates/styles/admin-custom.css

/* Hides the "Add" button for the Inputfield Page List Select Multiple field with name "my_pagelist_select_multiple" */
#wrap_Inputfield_my_pagelist_select_multiple a.PageListSelectActionToggleStart {
  display: none;
}

Hope this helps.

  • Like 3
Link to comment
Share on other sites

  • Pavel Radvan changed the title to [SOLVED] Disable "add" button in Page Reference field

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

×
×
  • Create New...