Skip to content

[Form] Add options "min" and "max" to NumberType #6732

@romaricdrigon

Description

@romaricdrigon

Hi,

At the moment, using the Range validation constraint, we can set up a min & max for a numeric value in an entity property.

Html5 offers min & max attributes for number inputs, so we can also enforce this client-side in any form:

$builder
    ->add('aNumber', 'number', array(
            'attr' => array('min' => 1, 'max' => 100)
    ))

It may be nice to offer min & max options for number field type. It seems pretty logical, as some other fields already have such attributes (ie max_length for text fields).

The syntax may be:

$builder
    ->add('aNumber', 'number', array(
            'min' => 1,
            'max' => 100
    ))

These attributes will be used client-side & the submitted object will be validated too.

What do you think?
I'm ok about contributing the code (& tests & doc), but I wanted the idea to be reviewed first.

Metadata

Metadata

Assignees

No one assigned

    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