再會!
我在我的 SuiteCRM 上創建了一個自定義驗證,如果它已經存在,它將驗證名字、姓氏和手機號碼。但我的問題是驗證作業后資料不會保存或更新。
檢查下面的view.edit.php代碼:
$javascript = <<<'EOT'
<script type="text/javascript" language="JavaScript">
function customJavascriptDuplicateValidation(thisview)
{
var firstname = document.getElementById('first_name').value;
var lastname = document.getElementById('last_name').value;
var mobile = document.getElementById('mobile_number').value;
var birthday = document.getElementById('birthday').value;
var email = document.getElementById('email_c').value;
var location = document.getElementById('location_code').value;
var consent = document.getElementById('consent_timestamp_date').value;
var salutation = document.getElementById('salutation').value;
$.post('index.php?entryPoint=checkDuplicateCustomers', { first_name: firstname, last_name: lastname, mobile_number: mobile }, function(data)
{
if (data == 'exists') {
$('#error_firstname_msg').html('<strong style="color:red;"> ✗ Already Used</strong>');
$('#error_lastname_msg').html('<strong style="color:red;"> ✗ Already Used</strong>');
$('#error_mobile_msg').html('<strong style="color:red;"> ✗ Already Used</strong>');
return check_form('EditView');
}else if (data == 'unique'){
$('#error_firstname_msg').hidden;
$('#error_lastname_msg').hidden;
$('#error_mobile_msg').hidden;
if(firstname != '' && lastname != '' && mobile != '' && birthday != '' && email != '' && location != '' && consent != '' && salutation != ''){
return check_form('EditView');
}else{
return check_form('EditView');
}
}else{
$('#error_firstname_msg').hidden;
$('#error_lastname_msg').hidden;
$('#error_mobile_msg').hidden;
return check_form('EditView');
}
});
}
</script>
EOT;
我修改了editviewdefs.php的保存按鈕
$viewdefs['Accounts']['EditView']['templateMeta']['form']['buttons'][0] = array(
'customCode' => '<input title="Save" accesskey="a" onclick="var _form = document.getElementById(\'EditView\'); _form.action.value=\'Save\'; if(customJavascriptDuplicateValidation(\'EditView\'))SUGAR.ajaxUI.submitForm(_form);return false;" type="submit" name="button" value="Save" id="SAVE">',);
當您單擊SAVE時,Native Valition 起作用。

如果單擊SAVE ,自定義驗證也有效:


填寫必填欄位并輸入唯一客戶資訊后。資料不會保存。
我對此的結論是關于我的自定義 javascript 代碼。因為如果我將下面的代碼放在$.POST函式之外,資料將保存,但是如果條件中的所有欄位都不是null/empty,自定義重復驗證將不起作用。
if(firstname != '' && lastname != '' && mobile != '' && birthday != '' && email != '' && location != '' && consent != '' && salutation != ''){
SUGAR.ajaxUI.showLoadingPanel();
return check_form('EditView');
}
uj5u.com熱心網友回復:
請忽略這個,我只需在下面添加此代碼即可解決此問題:
SUGAR.ajaxUI.showLoadingPanel();
var _form = document.getElementById('EditView');
_form.action.value='Save';
SUGAR.ajaxUI.submitForm(_form);
return check_form('EditView');
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/521587.html
