vitalets / angular-xeditable

Edit in place for AngularJS
http://vitalets.github.io/angular-xeditable
MIT License
1.91k stars 403 forks source link

fix bug several uiselect #487

Closed geoalex89 closed 8 years ago

geoalex89 commented 8 years ago

Firt of all sorry for my englis. I add my code for fix bug when there are several uiselect in the same template:

`//xeditable with ui-select angular.module('xeditable').directive('editableUiSelect', ['editableDirectiveFactory', function (editableDirectiveFactory) { var rename = function (tag, el) { var newEl = angular.element('<' + tag + '/>'); newEl.html(el.html()); var attrs = el[0].attributes; for (var i = 0; i < attrs.length; ++i) { newEl.attr(attrs.item(i).nodeName, attrs.item(i).value); } return newEl; };

    var match = [];
    var choices = [];
    var dir = editableDirectiveFactory({
        directiveName: 'editableUiSelect',
        inputTpl: '<ui-select></ui-select>',
        render: function () {
            this.parent.render.call(this);
            //fix bug model update
            this.inputEl.attr('ng-model', '$parent.$data');
            this.inputEl.append(rename('ui-select-match', match[this.inputEl.attr('name')]));
            this.inputEl.append(rename('ui-select-choices', choices[this.inputEl.attr('name')]));

        }
    });
    var linkOrg = dir.link;

    dir.link = function (scope, el, attrs, ctrl) {

        var matchEl = el.find('editable-ui-select-match');
        var choicesEl = el.find('editable-ui-select-choices');

        match[attrs.eName] = matchEl.clone();
        choices[attrs.eName] = choicesEl.clone();

        matchEl.remove();
        choicesEl.remove();

        return linkOrg(scope, el, attrs, ctrl);
    };

    return dir;
}]);`
ckosloski commented 8 years ago

Pull request #464 was already completed to fix multiple ui-select's on a page. A new release should be coming out shortly with the fix.

geoalex89 commented 8 years ago

ok thanks!!