Jump to content

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


eelkenet
 Share

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)?  

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