Asked  7 Months ago    Answers:  5   Viewed   39 times

Is there an easy way to set a default value for text form field?

 Answers

40

Can be use during the creation easily with :

->add('myfield', 'text', array(
     'label' => 'Field',
     'empty_data' => 'Default value'
))
Wednesday, March 31, 2021
 
anjan
answered 7 Months ago
65

You need to put any strings starting with @ in quotes:

arguments:
    ["@security.context", "@fos_user.user_manager"]

Reserved characters, like @, should be quoted. Unquoted @s were deprecated in Symfony 2.8. Symfony 3.0 will forbid you to use such definitions and will throw an exception.

If you don't have control over the bundle that registered the problematic configuration, send a pull request with a fix to the vendor. As a quick fix you can downgrade Symfony. 2.7 will work, as well as 2.8 (the later will only emit a deprecation notice).

Saturday, May 29, 2021
 
FWH
answered 5 Months ago
FWH
59

I ran into the same issue and found the following solution in the documentation: http://symfony.com/doc/current/book/testing.html#your-first-functional-test

To run your functional tests, the WebTestCase class bootstraps the kernel of your application. In most cases, this happens automatically. However, if your kernel is in a non-standard directory, you'll need to modify your phpunit.xml.dist file to set the KERNEL_DIR environment variable to the directory of your kernel:

<phpunit>
    <!-- ... -->
    <php>
        <server name="KERNEL_DIR" value="/path/to/your/app/" />
    </php>
    <!-- ... -->
</phpunit>

So check your phpunit.xml.dist configuration file and try to add the absolute path to your app-directory.

Hope it helps.

Friday, July 30, 2021
 
Bálint Molnár
answered 3 Months ago
20

You can pass a second option to options_for_select that indicates the selected value.

options_for_select(@user_groups.collect { |p| [p.name, p.id] }, @user.user_group)

Obviously I'm not sure how your models are set up, but if necessary you use a method like find to locate the entry you want.

Monday, August 16, 2021
 
test12345
answered 2 Months ago
68
from django.utils.functional import curry

class DetailsInline(admin.TabularInline):
    model = Details
    formset = DetailsFormset
    extra = 3

    def get_formset(self, request, obj=None, **kwargs):
        initial = []
        if request.method == "GET":
            initial.append({
                'label': 'first name',
            })
        formset = super(DetailsInline, self).get_formset(request, obj, **kwargs)
        formset.__init__ = curry(formset.__init__, initial=initial)
        return formset

From here: Pre-populate an inline FormSet?

Wednesday, September 15, 2021
 
edorian
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :