Question

what I have:

I change on of model attributes with help of x-editable.

What I need:

Check some conditions before make a change.

What a problem:

this.$el.find("#my-field").editable({
    type        : 'text',
    name        : myFieldTitle,
    value       : myCurrentValue,
    pk          : this.model.get('id'),
    url         : '',
    success     : function(response, newValue) {
        //PROBLEM: At this moment visual representation of a model has been already changed
        //no matter if condition is true or false
        if (condition)
          self.model.set(field.name, newValue);
    }
});

Question:

how can I change visual representation (of my model) with help of x-editable only after condition checking?

Was it helpful?

Solution

You should use the callback validate from X-Editable:

this.$el.find("#my-field").editable({
    [...]
    validate     : function(value) {

        if (condition)
          [...]
    }
});

Link: http://vitalets.github.io/x-editable/docs.html#editable

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top