[英]How can I display a single out of range message with the Range validator in Symfony2/3?
Symfony2中的Range約束允許您指定最小值和最大值,並根據輸入超出或低於限制顯示消息。
/**
* @Assert\Range(
* min = 120,
* max = 180,
* minMessage = "You must be at least {{ limit }}cm tall to enter",
* maxMessage = "You cannot be taller than {{ limit }}cm to enter"
* )
*/
如何指定與最小值或最大值無關的通用消息? 例如:
/*
* ...
* outOfRangeMessage = "You must be between {{ min }} and {{ max }} to enter."
* ...
*/
沒有這樣的outOfRangeMessage
參數。 有一個invalidMessage
參數,但只有在輸入根本不是數字時才會返回,這對我的目的不起作用。
最糟糕的方法是對min
和max
進行硬編碼並重復兩次消息,如下所示:
/*
* ...
* minMessage = "You must be between 120 and 180 to enter.",
* maxMessage = "You must be between 120 and 180 to enter."
* ...
*/
但這太可怕了。
沒有辦法做到這一點。 您只能在消息中使用limit
和value
參數。 您還可以覆蓋RangeValidator:validate
方法以添加更多參數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.