Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-10-02 13:39:11

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

custom field names

With the promise of the introduction of unlimited custom fields for 4.7 and until that happens, is there a way we could have a plugin which changes the name of the custom_field in the write tab depending on what section is chosen?

This will be more for usability rather than functionality. I am currently working on a design which does not necessarily need more than 10 CFs but their required contents will be different depending on the article’s section and there is no way I can give them names which can make sense for all sections.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#2 2016-10-02 14:35:20

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: custom field names

Maybe you can expand bot_cf_titles (still works in Textpattern 4.6) with a section dependence.

Offline

#3 2016-10-02 14:48:46

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

Re: custom field names

GugUser wrote #301900:

Maybe you can expand bot_cf_titles (still works in Textpattern 4.6) with a section dependence.

Hi GugUser and thanks for the feedback. The plugin is not quite was I was looking for as it just allows for more complex plugin names which I could have anyway such as img_ids_or_link_ids which of course is very confusing considering that the section selected is over the page’s fold.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#4 2016-10-03 10:08:58

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: custom field names

Yiannis, you can, of course, add extra custom fields with glz_custom_fields and use those rather than assigning different uses to the same custom field. That is probably simplest. Should you ever need to export your data some time in the future, you have distinct custom fields for distinct information.

But you can also do what you want with javascript added to the admin area (for example in the scripts area of bot_wtc or the new theme script option). I’m sure I saw a sample of this on the forum somewhere but can’t find it now. I found Dale has some similar examples in another thread.

But something like this (untested) should work:

$("select#section").change(function() {
	var value = $("select#section").val();

	if (value == "section-a") {
		$("label[for='custom-3']").text("My New Label");
	}

}).change();

…and so on. Add other label modifications for each custom field as needed and further if statements for other sections.

Note that you will need to return the labels back to their defaults too if you switch to your new section and then decide to switch back.

If you just need to change it for one section and otherwise retain the default, you can do:

	if (value=="section-a") {
		$("label[for='custom-3']").text("My New Label");
	} else {
		$("label[for='custom-3']").text("Default Label");
	}

but if you have a more involved setup, you can do an if-not-these-sections setup like this

	if (! (value == "section-a" || value == "section-b") ) {
		$("label[for='custom-3']").text("Default Label");
	}

(the ! means not and the || means or). It depends how complex your setup is.

Likewise, if your setup is complex, you could first store the default label values as variables, set new label values depending on the section currently selected and only change those custom-field labels that have changed. At some point it may be more efficient to do this with a switch/case arrangement instead of lots of if statements, but maybe someone else can supply that. There are lots of ways.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2016-10-03 10:16:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: custom field names

colak wrote #301897:

their required contents will be different depending on the article’s section

Reusing custom fields for different types of data is going to land you in hot water later, when we migrate to a proper table for the metadata.

I would follow jakob’s initial advice and use a different set of CFs for each distinct section, then dynamically switch them in and out using something like sed_section_fields (which’d need rewriting for 4.6.0) or bot_wtc.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB