如何删除 Gravity Forms 中无线电选项之间的相对价格?
How do I remove relative prices between radio options in Gravity Forms?
这是我的 "Options" 字段(来自 "Pricing Fields")的设置示例:
下面是 select 选择一个选项时的显示方式:
我想用期权的绝对价格代替相对定价。
从 Gravity Wiz 我找到了一种让价格完全消失的方法:
<script type="text/javascript">
function gform_format_option_label( fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId ) {
return fieldLabel;
}
</script>
但我已经尝试过可用的参数,它们会做一些奇怪的事情,比如每次你 select 另一个选项时添加一个额外的字段标签。
好吧,没有办法用 gform_format_option_label
给出的参数来做到这一点,除非你能想出一种方法来获取 fieldId
并查找字段的名称,我'我确定这是可能的,也是正确的方法,但我想不通。
为什么我不能直接使用 fieldLabel + ' $' + price
?因为如果你这样做,那么在每次点击时,你都会加上另一个价格,因为 fieldLabel
递归地 包括 价格!
为了解决这个问题,我这样做了:
<script type="text/javascript">
function gform_format_option_label( fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId ) {
if( fieldLabel.indexOf('$') == -1 ) fieldLabel += ' <span class="ginput_price">$' + price + '</span';
return fieldLabel;
}
</script>
非常 hacky,但它确实有效。它只是说,"Only tack on the price if there's not already a $
in fieldLabel
."
这是我的 "Options" 字段(来自 "Pricing Fields")的设置示例:
下面是 select 选择一个选项时的显示方式:
我想用期权的绝对价格代替相对定价。
从 Gravity Wiz 我找到了一种让价格完全消失的方法:
<script type="text/javascript">
function gform_format_option_label( fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId ) {
return fieldLabel;
}
</script>
但我已经尝试过可用的参数,它们会做一些奇怪的事情,比如每次你 select 另一个选项时添加一个额外的字段标签。
好吧,没有办法用 gform_format_option_label
给出的参数来做到这一点,除非你能想出一种方法来获取 fieldId
并查找字段的名称,我'我确定这是可能的,也是正确的方法,但我想不通。
为什么我不能直接使用 fieldLabel + ' $' + price
?因为如果你这样做,那么在每次点击时,你都会加上另一个价格,因为 fieldLabel
递归地 包括 价格!
为了解决这个问题,我这样做了:
<script type="text/javascript">
function gform_format_option_label( fullLabel, fieldLabel, priceLabel, selectedPrice, price, formId, fieldId ) {
if( fieldLabel.indexOf('$') == -1 ) fieldLabel += ' <span class="ginput_price">$' + price + '</span';
return fieldLabel;
}
</script>
非常 hacky,但它确实有效。它只是说,"Only tack on the price if there's not already a $
in fieldLabel
."