Jump to content
eelkenet

$config->js settings unavailable to new repeater item (using AJAX)

Recommended Posts

I just found out my fancy Float (Range) slider does not work with Repeaters, unless I disable AJAX for the repeater. This is because I pass the Inputfield's settings to the JS side of it through the $config->js route.
For every field I use the unique settings of that field. On the InputField I set these accordingly:

$otherFields = $this->config->js('InputfieldFloatRange') ? $this->config->js('InputfieldFloatRange') : [];

$this->config->js('InputfieldFloatRange', array_merge($otherFields, [
	"Inputfield_" . $this->attr("name") => [
		'precision' => $this->get("precision"),
		'rounding' => $this->get("roundingMethod"),
		'displayValueField' => $this->get('displayValueField'),
		'min' => $this->attr("min"),
		'max' => $this->attr("max"),
		'step' => (float) $this->attr("step")
	]
]));

And retrieve them on the Javascript side:

function getSettings(id) {
    return window.ProcessWire.config.InputfieldFloatRange[id];
}

var settings = getSettings(event.target.id); // from a 'change' event on the slider

However, when I create a new repeater item, it does not append that items slider's settings to the ProcessWire.config object, as I would have expected.

I could use an alternative path (using data-attributes in the actual field), but would prefer to keep this neatly.
So, does anybody know what I need to do to append my Inputfield's settings to $config->js dynamically, ie. upon creating a new repeater item (with AJAX)?  

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...