Formidable
Formidable copied to clipboard
Many constraints validation per fields
Hi @Gregwar,
I've a case with 2 constraints but only 1 is returned in check:
$form2->addConstraint('quantidade_assentos', function($form) {
if (empty($form->getValue('quantidade_assentos'))) {
return 'Quantidade de assentos é obrigatória!';
}
return null;
});
$form2->addConstraint('quantidade_assentos', function($form) {
if (!is_numeric($form->getValue('quantidade_assentos'))) {
return 'Quantidade de assentos deve ser número inteiro!';
}
return null;
});
Dump of getFields()
:
"quantidade_assentos" => NumberField {#613 ▼
#type: "number"
#min: "1"
#max: null
#step: "1"
#name: "quantidade_assentos"
#index: null
#hook: null
#attributes: array:3 [▶]
#value: ""
#required: true
#regex: null
#minlength: null
#maxlength: null
#prettyname: null
#readonly: false
#valueChanged: true
#constraints: array:2 [▼
0 => Closure {#606 ▶}
1 => Closure {#605 ▶}
]
#mapping: null
#language: English {#625 ▶}
}
Dump of errors:
array:1 [▼
0 => Error {#604 ▼
-field: NumberField {#613 ▶}
-message: array:2 [▼
0 => "value_required"
1 => "quantidade_assentos"
]
#language: English {#625 ▶}
}
]
In my view, there should be 2 errors because a empty value "" is catched in both constraints.
Any error in my logic?
Hello,
I belive you are correct, however the first error stops the check now as defined here https://github.com/Gregwar/Formidable/blob/master/Fields/Field.php#L210
Also, what you want here seems to be the html5 number
field
(Which is handled in Formidable)
Hi @Gregwar,
I'm using html5 number
field yes, but I desire to have many constraints and return many errors messages.
I'm using Zend_Form and desire and work in migration to Formidable. But this is a big problem for me because my forms has many validators(in Zend_Form)/constraints.
Ok, we should do some changes in the code to handle that, let's keep this open until
Le lun. 13 mars 2017 22:15, Silas Ribas Martins [email protected] a écrit :
Hi @Gregwar https://github.com/Gregwar,
I'm using html5 number field yes, but I desire to have many constraints and return many errors messages.
I'm using Zend_Form and desire and work in migration to Formidable. But this is a big problem for me because my forms has many validators(in Zend_Form)/constraints.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Gregwar/Formidable/issues/24#issuecomment-286246121, or mute the thread https://github.com/notifications/unsubscribe-auth/AAWZrpemw448Cqj2j4B9HlCnwSKRRUgmks5rlbHngaJpZM4Mbyv7 .
Many thanks!
Hi @Gregwar,
Any change?
Thk's
Actually I think that this is harder than it looks For instance, you don't want to have both messages "You should enter a value" and "The value should be an int", right?
Maybe that should be an option, like retrieving all the errors or the first one of every field
@silasrm Is this issue still relevant or can it be closed?