【发布时间】:2017-11-21 06:43:27
【问题描述】:
我需要检查字段phone_mobile 是否重复到数据库中。如果字段值不重复,则继续保存。
如果数据库中已经存在这样的电话,则显示警报消息并停止进程(表单提交)。
我的行动:
在文件./modules/Contacts/metadata/editviewdefs.php连接自定义js文件:
$viewdefs['Contacts']['EditView'] = array(
'templateMeta' => array(
'includes' => array (
array (
'file' => 'custom/include/javascript/custom_contact.js'
),
),
'form'=>array(
...
效果很好。
在custom_contact.js文件重载check_form(formname)函数中:
function check_form(formname)
{
if(formname === 'correct')
{
// This part does not work right for me
var _form = document.getElementById('EditView');
_form.action.value='Save';
SUGAR.ajaxUI.submitForm(_form);
return false;
}
if(formname === 'EditView')
{
// Ajax query works perfectly
$.ajax({
url : '/',
method : 'POST',
data : {},// some data
success : function(data) {
data = JSON.parse(data);
if(!data.success)
{
var text = 'The phone already exists';
return false;
}
check_form('correct');
}
});
}
return false;
}
但if(formname === 'correct') ... 块无法正常工作。
我需要停止 form_save 的工作并在必要时包含。
请帮助正确解决问题。我是 SugarCRM 的新手。
【问题讨论】:
-
@Adriano 我需要检查数据库中的电话号码。
-
为什么要调用一些JS函数来聚焦?或价值变化?如果验证失败,请完全禁用保存按钮。
-
@Star 请举例说明我如何做到这一点?
标签: php ajax validation sugarcrm suitecrm