3

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';
}
10
  • that should work, any errors, tried printing the value of value to the console? Only thing I would add is the curly braces to the if, e.g. if($.trim(value) == '') { return 'This field is required'; }. Commented Nov 19, 2015 at 14:20
  • @ martincarlin87 Can you show me with the fiddle?
    – User123
    Commented Nov 19, 2015 at 14:23
  • What you are trying to validate exactly ?
    – faressoft
    Commented Nov 19, 2015 at 14:29
  • @faressoft Iam trying to get validate input field on submit, with warning message " This field is required ".
    – User123
    Commented Nov 19, 2015 at 14:31
  • Do you wan't to validate on save or what ? The validation of the name field is working fine ! The condition is always false because the id is 4 not 2.
    – faressoft
    Commented Nov 19, 2015 at 14:36

1 Answer 1

2

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/

2
  • do you have any idea how to disable Add button in the same fiddle until we click on save button so that we can not get another blank fields.
    – User123
    Commented Nov 19, 2015 at 15:35
  • I suggests to use ng-disable="checkValid()" and inside that function check all fields if it is valid or not and return a boolean value.
    – faressoft
    Commented Nov 19, 2015 at 15:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.