Fixed Minor issue in custom_field_edit

sonnb

Well-known member
If we have a custom field (in XF, RM or others which use custom_field_edit) type "Drop down selection". In case this field is not required and in "Possible Choices:" have a value equal 0, then on rendering, XF will choose the choice has value 0 instead of blank choice.

Possible solution: Check if this field has a value in xen:selected
Code:
<option value="{$choice}" {xen:selected '{$field.hasValue} &&{$field.field_value} == {$choice}'}>{xen:raw $text}</option>
Instead of:
Code:
<option value="{$choice}" {xen:selected '{$field.field_value} == {$choice}'}>{xen:raw $text}</option>
 
I think a better fix is actually to use ===, as a field choice with a value of 0 could be selected instead of the user's choice if their choice is not a number (due to PHP's type coercion).
 
I think a better fix is actually to use ===, as a field choice with a value of 0 could be selected instead of the user's choice if their choice is not a number (due to PHP's type coercion).
Yes. It is also a solution. The reason why I used hasValue check is just to be sure it has a value.
 
Top Bottom