Search code examples
javascriptjqueryangularjsx-editable

How to validate xeditable inputbox


I am using xeditable to have inline editable functionality, but now I am stuck trying to validate my input.

Here is an example using jsFiddle

I tried the below code with no success.

validate: function(value) {
  if($.trim(value) == '') 
    return 'This field is required';
}

Solution

  • You can define a validation function like this:

    $scope.validateRequired = function(value) {
      if(!value)
        return "Required field";
    };
    

    Then use it with the event onbeforesave

    onbeforesave="validateRequired($data)"
    

    Please check:

    http://jsfiddle.net/NfPcH/11642/