I'm building a plugin that relies on Javascript to function correctly. Having tried different methods, I can't get the ID names to remain consistent.
Here's an example of the code that is being output.
<input type="text"
id="fields-slider-output"
name="fields[slider]"
value="539">
<span id="fields-value"></span>
<input
id="fields-input"
type="range"
name="fields[slider]"
value="539" min="0 max="1000" step="0">
The first input is a text input, and displays the ID as you would expect. The span element below only contains "fields-", and leaves out the name of the field. The same happens with the range input, which is the most surprising, as it's a form input with a name.
When using JavaScript, the "fields-" namespace is left out entirely, which means that the Javascript can't bind to an element.
$("#slider-input")[0].oninput = function () {
$('#slider-value').html(this.value);
};
I'm using this code from the Craft docs.
$id = craft()->templates->formatInputId($name);
$namespacedId = craft()->templates->namespaceInputId($id);
I've also looked into the namespacing HTML docs (http://buildwithcraft.com/docs/apis/templatesservice#namespacing-html) with little success.
Does anyone know a possible solution to this? Bearing in mind this Fieldtype requires Matrix support, so using a class instead of an ID is not an option.
Thanks.