ZF2 - 始终需要输入类型“数字”?

I have this code in my Form.php

$this->add(array(
    'name' => 'unidades_andar',
    'type' => 'number',
    'attributes' => array(
        'class' => 'form-control',
    ),
));

And this in my view.phtml

<?php echo $this->formElement($form->get('unidades_andar')); ?>

And when I try to submit the form, I have this error:

Array ( [unidades_andar] => Array ( [isEmpty] => Value is required and can't be empty ) )

I already tried to set "required => false".

And if I change the type to TEXT instead of NUMBER, it works.

But why can't I use the type number? It seem to always be required...

If you look at the source of of zend-framework/zend-form/src/Element/Number.php you can see that this field is being set to required by default.

/**
 * Provide default input rules for this element
 *
 * Attaches a number validator, as well as a greater than and less than validators
 *
 * @return array
 */
public function getInputSpecification()
{
    return array(
        'name' => $this->getName(),
        'required' => true,
        'filters' => array(
            array('name' => 'Zend\Filter\StringTrim')
        ),
        'validators' => $this->getValidators(),
    );
}

So you need to do something like this

public function getInputFilterSpecification()
{
    return [
        [
            "name"=>"unidades_andar",
            'required' => false,
            'allow_empty' => true, // this will allow submitting empty values like ''
        ],
    ];
}