Is there a JavaScript equivalent to namespaceInputName?

My fieldtype settings are doing some interesting JavaScript gymnastics. Part of the process involves creating an array on the fly (so when the fields are submitted, the array will be stored properly). Currently, it's working great using JS code like this:

function(subfield, type, value) {
    var name = 'types[MyPlugin_MyFieldtype][dataArray][' + subfield + '][' + type + ']';
    var hidden = '<input type="hidden" name="' + name + '" value="' + value + '" />';
    // Then add that hidden field to the DOM

Here's where it gets interesting... This prefix works great as long as I'm building a normal field:


But, it stops working when I try to build my field within a Matrix. Because when my field is nested within a Matrix, the prefix should look something like this:


Is there any way (in JavaScript) to automatically set that prefix properly?

  • I've actually found a completely different way to go about this... but I'll leave this question up in case anyone has a legitimate answer for it.
    – Lindsey D
    Jun 24 '15 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.