0

I have an entity in My Symfony project with a field "brand' that is nullable false. I want it to be required true for the client side. However, it isn't working. Did something change in the bundle? I can't find what the problem is.

The entity:

/**
 * @var string
 *
 * @ORM\Column(name="brand", type="string", length=255, nullable=false)
 */
private $brand;

The form:

    ->add('translations', 'a2lix_translations', array(
                'fields' => array(
                    'brand' => array(
                        'field_type' => TextType::class,
                        'required'   => true
                    ),
                )
            )
        )`

I also tried this but still no required appears in the front:

    ->add('translations', 'a2lix_translations', array(
                'fields' => array(
                    'brand' => array(
                        'field_type' => TextType::class,
                        'locale_options' => array(            
                              'en' => array(
                                'required' => true
                             ),
                              'fr' => array(
                                'required' => true
                            )
                        )
                    ),
                )
            )
        )`

The result in both cases in the browser is:

<input type="text" id="video_form_translations_en_brand" name="video_form[translations][en][brand]" maxlength="255" class="form-control">
unadivadantan
  • 363
  • 4
  • 14

1 Answers1

0

I just corrected the problem setting both languages as required locales in my config.yml. Now, my required true fields have the required attribute and the non required fields remains non required.

# A2lix Configuration
a2lix_translation_form:
    locale_provider: default
    locales: "%languages%"          # locales available for the forms
    default_locale: "%locale%"      # default locale
    required_locales: [en, fr]         # requireds locales (not all fields will be required - only the ones with required true)
    manager_registry: doctrine
    templating: "A2lixTranslationFormBundle::default.html.twig"
unadivadantan
  • 363
  • 4
  • 14