Home Forums Bug Reports Select2 fields not rendering due to a bad loop in acf.maybe_get


Select2 fields not rendering due to a bad loop in acf.maybe_get

  • Select2 fields won’t render at all since if no valid version is found on the acf.select2 object, the acf.select2.init function will bail early. The reason why the version isn’t found is because in acf.select2.ready the version gets defined by checking if the ‘Select2’ variable exists in the global scope. The check is done by an intermediate function called acf.maybe_get. In that function, a keys array gets created out of the key argument passed (in this case, it’s "Select2", which renders out a keys array of ["Select2"]). This keys array is looped via a for in loop instead of a standard for loop incrementing an index on each iteration… But that’s not the issue! The issue is that the for in loop doesn’t check if the array has the current iterating key as an own propery, i.e. keys.hasOwnProperty(key). This becomes a bug when the Array.prototype has properties that have their property descriptor’s enumerable property to true, which is the default when defining a property on an object. In my case, I had polyfills set up for a couple ES6 array methods, which were looped over in acf.maybe_get’s for in loop. The solution would be to either use a proper incremental for loop iterating the array indices​ or just check if the current iterated property/key is the array’s own property and not an prototypial method.

  • You should submit this information by submitting a new support ticket here

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Select2 fields not rendering due to a bad loop in acf.maybe_get’ is closed to new replies.