kbond / ZenstruckFormBundle

Provides Twitter Bootstrap form theme, a help type extension, Ajax/Tunnel/Select2 entity form types and javascript helpers
25 stars 14 forks source link

[Q] How to display other label than ID after saving #4

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hi,

I have a question regarding the value of a zenstruck_ajax_entity field after saving. When i search for a value, i see this:

image

The label is a combination of a teamName and seasonName, fetched via the URL option. After saving, it shows the ID.

image

Is it possible to alter the label?

kbond commented 11 years ago

The label is found by the entity's __toString() method: https://github.com/kbond/ZenstruckFormBundle/blob/master/Form/DataTransformer/AjaxEntityTransformer.php#L33

Do you have that setup correctly?

ghost commented 11 years ago

Ah, i forgot i had added this to my entity. Thanks a lot!

<?php public function __toString() { return strval($this->getId()); } ?>

kbond commented 11 years ago

No problem, thanks for the feedback.

I have added a note about __toString() in the docs