Monday, December 19, 2016

Sitecore WFFM targeting field inputs with jQuery

With current and older versions of Sitecore's Web Forms for Marketers module, it can often be necessary to make use of jQuery or JavaScript to extend functionality of the form. A common example would be conditional logic, such as if field A has value/selection show field b.

The problem is that the fields output with long ids which contain information such as the form id along with containing placeholder and ordering of the element. Instead of targeting by such a long id, for any custom WFFM form logic I prefer to target via the field id alone.

This can be done by using the jQuery attribute ends with selector. An example for an input field would be:
$("input[id$='9047F37B17F245AE9F56ABBDB1934510']")
This will find the input element for a given Sitecore form field.

No comments:

Post a Comment