Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Having first control in the page with tabs to be focused
Message
 
 
General information
Forum:
AngularJS
Category:
Troubleshooting
Miscellaneous
Thread ID:
01655956
Message ID:
01655977
Views:
20
>>>Do you mean you tried the ng-focus directive in angularjs ?
>>
>>I didn't yet try ng-focus, let me try it. How should I use ng-focus to focus the first element?
>>
>>I tried using just focus="true" (for all controls in a loop) but this didn't work.
>
>Don't think there's any such attribute. ng-focus takes an expression which evals to true/false. You could back that with a method that returns true when the relevant pane is selected.
>Although, top of my head, I'm not sure how you should do that (I'm rapidly trying to forget AngularJs and focussing on Angular 2)
>
> I think my problem is that I'm using nav-tabs. I found related discussion but it's a bit over my head
>>
>>https://stackoverflow.com/questions/24491779/set-focus-to-an-input-within-a-bootstrap-tabcontent-on-tab-change
>>
>>and I don't know how should I incorporate that in my own code.
>
>Those are JQuery solutions (which should work)
>
>
>>BTW, can you please also help with my other thread? When I left to sleep last night (I worked till 12 am) I realized my solution is not going to work in the case my message returns nothing and I do want the Save to fire. Right now it sort of works because I was testing with returning my error message.
>>
>>I am not sure how to get the logic to work, e.g. have my method that may call server call return its result and only after that fire the Save if it's OK.
>
>What do you mean by 'message returns nothing' ?

My colleague helped me with that second problem already. Here is the new code:
 /**
     * @protected
     * @returns {ng.IPromise}
     */
    resTypesCrudController.prototype.verifySingleDefault = function () {
        var self = this;
        var deferred = services.Deferred;

        if (this.originalIsDefault === false && this.model["isDefault"] === true) {
           services.ResTypes.getDefaultStatusMessage(this.model["resTypeId"])
                .then(function (message) {
                    if (message) {
                        self.notifyError(message);
                        deferred.resolve(false);
                    } else {
                        deferred.resolve(true);
                    }
                })   
               .catch(function (error) {
                   self.notifyError(error);
                   deferred.reject(error);
               });
           
        } else {
            deferred.resolve(true);
        }
        
        return deferred.promise;
    };

    /**
     * @public
     * @returns {void}
     */
    resTypesCrudController.prototype.new = function () {
        var self = this;
        
        this.verifySingleDefault()
            .then(function (saveIsAllowed) {
                if (saveIsAllowed) {
                    SW.CrudController.prototype.new.call(self);
                }
            });
    };
I knew I wanted to use then but it was not exactly clear how.

As for the first problem, I understand that they are jQuery solutions and that's why I am not sure how would it fit into the controller's code. Or how exactly should I implement that and where.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform