Skip to content

[Form] Constraint HTML attributes guessing completely ignored #7181

@marcospassos

Description

@marcospassos

Complementing #6645.

With this configuration:

    <entity name="Acme\DemoBundle\Entity\Product">
        <id name="id" column="id" type="integer">
            <generator strategy="AUTO" />
        </id>
        <field name="name" column="name" type="string" />
        <field name="presentation" column="presentation" nullable="true" />
        <field name="code" column="code" type="string" />
    </entity>
    <class name="Acme\DemoBundle\Model\Product">
        <property name="name">
            <constraint name="NotBlank" />
            <constraint name="Length">
                <option name="min">2</option>
                <option name="max">255</option>
            </constraint>
        </property>

        <property name="code">
           <constraint name="NotBlank" />
           <constraint name="Regex">
                <option name="pattern">/^\d+/</option>
            </constraint>
            <constraint name="Length">
                <option name="min">2</option>
                <option name="max">255</option>
            </constraint>
        </property>
    </class>

The result is:

<form method="post" novalidate="novalidate">
    <div id="product">
        <div>
            <label for="product_name" class="required">Name</label><input type="text" id="product_name" name="product[name]" required="required"/>
        </div>
        <div>
            <label for="product_presentation" class="required">Presentation</label><input type="text" id="product_presentation" name="product[presentation]" required="required"/>
        </div>
        <div>
            <label for="product_code" class="required">Code</label><input type="text" id="product_code" name="product[code]" required="required"/>
        </div>
        <input type="hidden" id="product__token" name="product[_token]" value="..."/>
    </div>
    <button type="submit">Submit</button>
</form>

Expected:

  • Name: required=true, minlength=2, maxlength=255
  • Presentation: required=false
  • Code: required=true, pattern=/^\d+/, minlength=2, maxlength=255

Here is the symfony-standard fork to reproduce the issue:
https://github.com/marcospassos/symfony-standard/tree/master/src/Acme/DemoBundle

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy