2

I am using xeditable for my project.

Fiddle

Above is the fiddle.

I want to have save and send invite button instead of save button only while click on add button.

When I click on edit it should be Save button.

I tried using another forom to display save and send invite button with no result.

<form editable-form name="rowform" id="hidebuttons12" ng-show="rowform.$visible" class="form-buttons form-inline" shown="">
    <button type="button" ng-disabled="rowform.$waiting" ng-click="rowform.$cancel(); isCollapsed2 = !isCollapsed2" ng-hide="hideButton[$index]" class="btn btn-default">cancel</button>
    <button type="submit" ng-click="saveUser(); isCollapsed2 = !isCollapsed2" ng-disabled="rowform.$waiting" ng-hide="hideButton[$index]" class="btn btn-primary">Save changes</button>
</form>

<form class="text-right" editable-form name="rowform1" ng-show="rowform1.$visible" class="form-buttons form-inline" shown="inserted == user">
    <button type="button"  ng-click="removeUser($index);" class="btn btn-default">cancel</button>
    <button type="button" ng-click="saveUser(); sendInvite(); isCollapsed2 = !isCollapsed2" ng-disabled="rowform1.$waiting" class="btn btn-primary">{{buttonText}}</button>
</form>

Or can we have all three buttons in one form and hide and show it based on button click.

Can anyone help me with this issue.

1 Answer 1

1

Edit : Following your comment, new Fiddle : http://jsfiddle.net/NfPcH/11280/

The same way, you just need to add : ng-show="user.id < 0" to the save button


I updated your fiddle : http://jsfiddle.net/NfPcH/11278/

I'm not an expert in xeditable so maybe there is a better solution. The solution I used is setting user.id = -1 when you add new user.

And setting user.id = users.length+1 only during save.

Therefore you can use ng-show="user.id < 0" on the button you want to show only for new users.

Code:

$scope.saveUser = function (data, user) {
    //$scope.user not updated yet
    user.id = $scope.users.length + 1;
    angular.extend(data, {
        id: user.id
    });
    return $http.post('/saveUser', data);
};

// add user
$scope.addUser = function () {
    $scope.inserted = {
        id: -1,
        name: '',
        status: null,
        group: null
    };
    $scope.users.push($scope.inserted);
};

View:

<button type="button" ng-show="user.id < 0" ng-click="saveUser(); sendInvite();" ng-disabled="rowform.$waiting" class="btn btn-primary">Send invite</button>
Sign up to request clarification or add additional context in comments.

5 Comments

@Steevan Updated the fiddle for you. But I think it was so easy you could have done it yourself ;) If (user.id < 0) means it's a new user, then you just need to add ng-show="user.id > 0" to the save button to remove it from new users view
Thanks alot for the answer.
Iggy Iam unable to save any data.
@User123 what do you mean ?
While adding new user are you able to save it?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.