Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$scope.setPlaceHolder(newValue) #19

Closed
sargin48 opened this issue Apr 5, 2019 · 7 comments
Closed

$scope.setPlaceHolder(newValue) #19

sargin48 opened this issue Apr 5, 2019 · 7 comments
Assignees
Labels

Comments

@sargin48
Copy link

sargin48 commented Apr 5, 2019

"$scope.setPlaceHolder is not a function"

@postb99
Copy link

postb99 commented Apr 5, 2019

Please give more info. The component is compatible with ionic 1 and may not work with newest ionic.

@sargin48
Copy link
Author

sargin48 commented Apr 5, 2019

Please give more info. The component is compatible with ionic 1 and may not work with newest ionic.

My ionic version 1.3.2

@postb99
Copy link

postb99 commented Apr 5, 2019

I don't find "setPlaceHolder" in the component code, what's your code?

@sargin48
Copy link
Author

sargin48 commented Apr 5, 2019

I don't find "setPlaceHolder" in the component code, what's your code?

(function(){

    var _template = [
        "<div class='selectBox {{ngSelectBoxClass}}' ng-click='show()'>",
        "<span class='selected {{ngPlaceholderClass}}'>{{label}}</span>",
        "<span class='selectArrow'>&#9660</span>",
        "<input type='hidden' ng-model='ngSelectedValue' name='{{ngHtmlName}}' dynamic-name ng-required='{{ngIsRequired}}'/>",
        "</div>"
    ].join("\n");

    angular.module('$selectBox', []).directive('selectBox', function () {

        return {
            restrict: 'E',
            require: ['ngModel' ],
            template: _template,
            scope: {
                ngSelectedValue: "=",
                ngTitle: "@",
                ngItemName: "@",
                ngItemId: "@",
                ngData: "@",
                ngPopup: "@",
                ngPopupClass: "@",
                ngHtmlName: "@",
                ngIsRequired: "@",
                ngPlaceholder: "@",
                ngHeaderClass: "@",
                ngSelectChanged: "&",
                ngPlaceholderClass: "@",
                ngSelectBoxClass: "@"
            },
            controller: ['$scope', '$element', '$ionicModal', '$ionicPopup', '$parse', function ($scope, $element, $ionicModal, $ionicPopup, $parse) {

                $scope.ngPlaceholder = ($scope.ngPlaceholder) ? $scope.ngPlaceholder : '';
                $scope.ngIsRequired = ($scope.ngIsRequired) ? JSON.parse($scope.ngIsRequired || false) : false;
                $scope.ngPopup = ($scope.ngPopup) ? JSON.parse($scope.ngPopup || false) : false;
                $scope.ngPopupClass = ($scope.ngPopupClass) ? $scope.ngPopupClass : '';
                $scope.label = $scope.ngPlaceholder;
                $scope.ngPlaceholderClass = ($scope.ngPlaceholderClass) ? $scope.ngPlaceholderClass : '';
                $scope.ngSelectBoxClass = ($scope.ngSelectBoxClass) ? $scope.ngSelectBoxClass : '';

                $scope.show = function () {
                    var val = $parse($scope.ngData);
                    $scope.ngDataObjects = val($scope.$parent);
                    $scope.ngHeaderClass = ($scope.ngHeaderClass) ? $scope.ngHeaderClass : "";
                    if(JSON.parse($scope.ngPopup || false)) {
                        $scope.showPopup();
                    } else {
                        $scope.showSelectModal();
                    }
                };
                $scope.showSelectModal = function () {
                    $scope.renderModal();
                    $scope.modal.show().then(function(modal) {
                        $scope.modal.el.style.zIndex = 99;
                    });
                };
                $scope.showPopup = function () {
                    $scope.renderPopup();
                };

                $scope.closeSelectModal = function () {
                    if($scope.modal)
                        $scope.modal.hide();
                };
                $scope.closePopup = function () {
                    if($scope.popup)
                        $scope.popup.close();
                };

                $scope.$on('$destroy', function (id) {
                    if($scope.modal)
                        $scope.modal.remove();
                });

                $scope.$watch('ngPlaceholder', function (newValue, oldValue) {
                  if (oldValue == $scope.label) {
                    $scope.setPlaceholderLabel(newValue)
                  }
                  $scope.setPlaceHolder(newValue)
                });

                $scope.$watch('ngSelectedValue', function (newValue, oldValue) {
                    //console.log('selected value changed from ', oldValue, ' to ', newValue);
                    if(undefined !== newValue) {
                        var val = $parse($scope.ngData);
                        $scope.ngDataObjects = val($scope.$parent);
                        var i=0, len=$scope.ngDataObjects.length;
                        for (; i<len; i++) {
                            if ($scope.ngDataObjects[i][$scope.ngItemId] == newValue) {
                                //console.log('found descr for ', newValue, ' = ',$scope.ngDataObjects[i][$scope.ngItemName]);
                                $scope.setPlaceholderLabel($scope.ngDataObjects[i][$scope.ngItemName]);
                            }
                        }
                    } else
                        $scope.setPlaceholderLabel($scope.ngPlaceholder);
                });

                $scope.renderModal = function () {
                    $scope.modal = $ionicModal.fromTemplate(
                          '<ion-modal-view id="select" class="ionic-select-enable '+$scope.ngPopupClass+'">'
                        + '<ion-header-bar class="' + $scope.ngHeaderClass + '">'
                        + '<h1 class="title">' + $scope.ngTitle + '</h1>'
                        + ' <a ng-click="closeSelectModal()" class="button button-icon icon ion-close ionic-select-enable"></a>'
                        + '</ion-header-bar>'
                        + '<ion-content>'
                        + '<ion-list class="ionic-select-enable">'
                        + '<ion-item class="ionic-select-enable" ng-click="clickItem(item);' + '" ng-repeat="item in ngDataObjects" ng-bind-html="item[\'' + $scope.ngItemName + '\']"></ion-item>'
                        + '</ion-list>'
                        + ' </ion-content>'
                        + '</ion-modal-view>', {
                        scope: $scope,
                        animation: 'slide-in-right',
                        backdropClickToClose : false
                    });
                };

                $scope.renderPopup = function () {
                    $scope.popup = $ionicPopup.alert({
                        title: $scope.ngTitle,
                        scope: $scope,
                        template: '<ion-list class="ionic-select-enable">'
                        + '<ion-item class="ionic-select-enable item-text-wrap" ng-click="clickItem(item);' + '" ng-repeat="item in ngDataObjects" ng-bind-html="item[\'' + $scope.ngItemName + '\']"></ion-item>'
                        + '</ion-list>',
                        cssClass: '' + $scope.ngPopupClass
                    });
                };

                $scope.clickItem = function (item) {
                    $scope.ngSelectedValue = item[$scope.ngItemId];
                    $scope.label = item[$scope.ngItemName];
                    $scope.ngPopup ? $scope.closePopup() : $scope.closeSelectModal();
                    $scope.ngSelectChanged({selectedValue: $scope.ngSelectedValue});
                };

                $scope.setPlaceholderLabel = function(label) {
                    $scope.label =  label;
                };

                $scope.setPlaceHolder = (newValue) => {
                    $scope.placeHolder = newValue;
                }

                $scope.$on('reset', function(){
                    $scope.setPlaceholderLabel($scope.ngPlaceholder);
                    $scope.ngSelectedValue = null;
                });
            }],
            compile: function ($element, $scope) {
                var input = $element.find('input.selected');
                angular.forEach({
                    'name': $scope.name,
                    'ng-model': $scope.ngSelectedValue
                }, function (value, name) {
                    if (angular.isDefined(value)) {
                        input.attr(name, value);
                    }
                });
            }
        };
    }).directive('dynamicName', function() {
        return {
            restrict: 'A',
            priority: -1,
            require: ['ngModel'],
            link: function (scope, element, attr, ngModel) {
                ngModel[0].$name = attr.name;
            }
        };
    });
//# sourceMappingURL=selectBox.js.map
})();

Edit: code syntax coloration

@sargin48
Copy link
Author

sargin48 commented Apr 5, 2019

i add this codes but it is workaround

$scope.setPlaceHolder = (newValue) => { $scope.placeHolder = newValue; }

@Xarkam Xarkam added the bug label Apr 5, 2019
@postb99
Copy link

postb99 commented Apr 5, 2019

Thanks, it's indeed missing. Keep your workaround until I republish it tomorrow :-)

@sargin48
Copy link
Author

sargin48 commented Apr 5, 2019

Thanks, it's indeed missing. Keep your workaround until I republish it tomorrow :-)

Thank you for the quick reply

@postb99 postb99 closed this as completed in 7166e65 Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants