Jump to content

How to set Inputfield settings dynamically via code?


bernhard
 Share

Recommended Posts

This one is a little bit special... I want to set an Inputfield setting at runtime via code. This works great for changing Inputfield labels or description and having everything under GIT. I'm using ProcessPageEdit::buildForm to modify the Inputfield before it gets rendered.

The problem is that this technique does not work in several situations when AJAX is involved. For example I can not set InputfieldFile settings like max filesize or another example is the noLang = 1 setting that hides the multilanguage field descriptions of the Inputfield and shows only one inputfield. When using the buildForm hook, both settings modifications have no effect on newly uploaded files. That means the max filesize will never get checked and the setting noLang = 1 does also only work for existing files. When I upload a file it shows both language inputfields for the description and shows one just after saving the page (because then the buildForm hook knows about the file where to set noLang = 1).

Any ideas where I could hook into to modify the settings stored in the database as early as possible? Do you understand my problem / question? ? 

Link to comment
Share on other sites

  • 1 month later...

Hi @kongondo

I did not find a solution to this until now. I think there is none in general. InputfieldCkeditor has a custom implementation for that need 

var editor;
if(typeof ProcessWire.config[configName] != "undefined") {
	var editor = CKEDITOR.replace(editorID, ProcessWire.config[configName]);
} else if(typeof $editor.attr('data-configdata') != "undefined") {
	// allow for alternate option of config data being passed through a data attribute
	// useful for some dynamic/ajax situations
	var configData = JSON.parse($editor.attr('data-configdata'));
	ProcessWire.config[configName] = configData;
	var editor = CKEDITOR.replace(editorID, configData);
}
if(editor) {
	ckeInitEvents(editor);
	$editor.addClass('InputfieldCKEditorLoaded');
}

So with CKEditor you can pass through custom settings via data-configdata. But that's also only related to the display part of the Inputfield. Regarding ajax processing on the backend I have not found any other way than setting the values directly in the DB (meaning to create a dedicated field for every different setting).

I have not looked into how the template overriding feature for fields works. Maybe there is some hookable method that could be used to modify the settings based on the template just via code? https://processwire.com/blog/posts/pw-3.0.145/#field-template-context-override-settings

If you find anything please let me know ? 

  • 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...