Jump to content

updating multiple fields at the same time


Joe
 Share

Recommended Posts

I have a site settings page, where the site admin can make general settings that will apply to all pages that use a certain template (most pages on the site). Additionally I want to allow for a choice per page that will override the general setting if selected.

Example: choice to have a one or two column layout.

Now if the admin changes the setting for all pages the individual page settings should be reset to the general setting's value (which would from then on be their default value and could be changed on pages that should be exceptions to this.)

I have looked at the API, but so far not come up with the solution (though I suspect it is a fairly obvious one).

If the user changes the value of the field (check-box in this case) that represents the general setting, at the same time the corresponding fields for all individual pages should be set to the same value.

I hope this is clear, thanks for your help!

Link to comment
Share on other sites

Well, technically speaking, not at the same time, but immediately after changing the general settings. :)

A bit more infos would be nice. How do your current selector / API calls look like? What's the relation? Is there a hierarchy (parent -> children), or just "all pages with template X"? What does your logic for the frontend look like?

A simple way would be to create another field in the parent (if you have a hierarchical structure) acting as a flag. If your admin wants to override all pages with a general setting valid for all pages, that flag would be changed from 0 to 1 (or whatever you choose). In your frontend / tpl logic, you'd first read that flag value, and only respect individual page settings if it's set to 0.

  • Like 1
Link to comment
Share on other sites

Thank you Dragan!

A bit more infos would be nice. How do your current selector / API calls look like? What's the relation? Is there a hierarchy (parent -> children), or just "all pages with template X"? What does your logic for the frontend look like?

Well, I have a general settings page. There you can make a choice, in this case mark a check-box. This value is then read and applied in the page template (all pages that use this template). In the page's edit view you also have a field (could be a drop-down) which overrides the general setting if set to another value (also applied in the template when outputting the page and overriding the general setting).

A simple way would be to create another field in the parent (if you have a hierarchical structure) acting as a flag. If your admin wants to override all pages with a general setting valid for all pages, that flag would be changed from 0 to 1 (or whatever you choose). In your frontend / tpl logic, you'd first read that flag value, and only respect individual page settings if it's set to 0.

Well, I'm not really sure. The site settings page is not the parent of the other pages. I still have to work out how to set this flag...

Anyway, I have now resolved this actual issue in a different way: I'm doing without the automatic reset - an individual choice per page will be retained regardless of the general setting. Probably just as useful.

It would still be interesting though if there is an elegant way of setting all fields of the same type to the same value on all pages, for example if a template contains a choice like "use a blue background" (yes or no) to reset that to "no" for all pages using this template.

Edited by Joe
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...