2012-11-09 126 views
4

即時通訊嘗試讓jquery驗證到我的symfony 2項目很長一段時間。它使用默認消息正常工作。但不能到那裏定製消息。輸入名稱存在問題。當我嘗試這樣的事情:Symfony 2中的jQuery驗證

rules: { 
    xxx_backbundle_offerstype[title]: "required" 
},messages: { 
    xxx_backbundle_offerstype[title]: "This field is required" 
} 

我得到這個錯誤「缺少id後運營商」。我想,這是JS錯誤,但我不知道,如何解決它。 它實際上有可能,使用jquery驗證inf symfony。

感謝您的任何提示

回答

3

嘗試下面,如果嵌入在HTML中JavaScript中使用單引號

rules: { 
    'xxx_backbundle_offerstype[title]': "required" 
},messages: { 
    'xxx_backbundle_offerstype[title]': "This field is required" 
} 
+0

非常感謝。它解決了我的問題。 – gavec

+0

您好,歡迎您先生! – Gowri

2

,你可以這樣做(至少我做這種方式):

rules: { 
    '{{ form.foo.vars.full_name }}': 'required' 
}, 
messages: { 
    '{{ form.foo.vars.full_name }}': 'This field is required!' 
} 

通過這樣做,你會不會當你更新你的表單項的名字來更新你的腳本。