How to display error message for field validation in SugarCRM?

时间:2017-11-13 06:19:06

标签: sugarcrm

Using SugarCRM v6.5.26 . I need to display inline error message instead of "alert" for validation of last name.

JavaScript file path (sample code is given):

/custom/modules/Contacts/js/editview.js

$('input#last_name').on('change', function () {
      var node = $(this);
      node.val(node.val().replace(/[^a-z]/g, ''));
      alert("Please enter only charcter");
});

Again, i don't want to show alert, only inline message.

1 个答案:

答案 0 :(得分:1)

这与javsacrip / jquery错误处理有关,你也可以在google上找到很多逻辑。

请尝试以下代码:

$('input#last_name').on('change', function () {      
    handleLastNameValidation();
    return false;
});

 var clickAttr = $("#SAVE_HEADER").attr("onclick"); 
 $("#SAVE_HEADER").attr("onclick","return handleLastNameValidation(); "+clickAttr);


function handleLastNameValidation(){

    clear_all_errors();

    var node = $('input#last_name');
        current_val = node.val();
        trimmed_val = node.val().replace(/[^a-z]/g, '');

    if( current_val != trimmed_val || trimmed_val =='')
    {
        add_error_style('EditView', 'last_name', 'Please enter correct value for last name',true);
        return false;
    }
    else 
    {
        return true;
    }

    return false;
}