If a Choice constraint receives choices from a PHP callback:
<?php
namespace App\Entity;
use Symfony\Component\Validator\Constraints as Assert;
class User
{
#[Assert\Choice(callback: [Util::class, 'getGenders'])]
private ?string $gender = null;
}<?php
namespace App\Entity;
class Util
{
public static function getGenders(): array
{
return ['male', 'female'];
}
}provide the same callback on the JavaScript side:
$('form#user').jsFormValidator({
callbacks: {
'App\\Entity\\Util': {
getGenders: function() {
return ['male', 'female'];
}
}
}
});Pure JavaScript:
var field = document.getElementById('user');
FpJsFormValidator.customize(field, {
callbacks: {
'App\\Entity\\Util': {
getGenders: function() {
return ['male', 'female'];
}
}
}
});You can also use the simplified callback form described in 3.5.2 when the method name is unique.