我需要在表單的“提交”事件上設定不同的 JS 事件。twig模板生成的表單為:
{{ form_start(theForm)}}
{{ form_row(theForm.name) }}
{{ form_row(theForm.lastName) }}
...
{{ form_end(theForm) }}
在JS檔案中:
$('form').on('submit', function(e) {
if (new) {
//do some staff
} else {
//do the other staff
}
});
如何定義用戶是否在此表單中添加新條目或更新現有條目?
uj5u.com熱心網友回復:
您可以檢查表單是否有 id:
$('form').on('submit', function(e) {
let new = {{ form.vars.value.id }};
//if creation, new will be null; else will have the id of existing
...
});
但建議有兩個twig檔案,一個用于新的,另一個用于更新
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/368139.html
標籤:javascript symfony 枝条
