お世話になっております。
angularJS(1.7.2)を使用して登録/更新が出来るページを作ろうとしております。
下記のソースで実行するとgetSeries()を実行した時点でフォーカスがフォームのどの欄からも外れてしまいます。
画面が更新されることによって外れると思うのですが、それまであった箇所に、フォーカスを自動的に合わせたいと考えております。
お分かりになる方いらっしゃいましたらよろしくお願いいたします。
<tr ng-repeat="series in serieses"> <td class="name"><input type="text" class="form-control" ng-model="series.name" ng-blur="setSeries(series.id)"></td> <td class="sequence"><input type="number" class="form-control" ng-model="series.sequence" ng-blur="setSeries(series.id)"></td> </tr> <tr> <td class="name"><input type="text" class="form-control" ng-model="seriesNameNew" ng-blur="setSeries(0)"></td> <td class="sequence"><input type="number" class="form-control" ng-model="seriesSequenceNew" ng-blur="setSeries(0)"></td> </tr> ------------------------------------------------------------- $scope.setSeries = function(id){ var name; var sequence; //登録の場合 if(!id){ name = $scope.seriesNameNew; sequence = $scope.seriesSequenceNew; } //更新の場合 if(id){ $scope.serieses.forEach(function(series){ if(series.id==id){ name = series.name; sequence = series.sequence; } }); } //Ajaxでシリーズを更新 $http({ method: 'POST', url: '/ajax/setSeries', params:{ id:id, name:name, sequence:sequence } }).then(function onSuccess(data,status,headers,config){ //正常処理 //シリーズを再取得 getSeries(); //新規登録欄消去 $scope.seriesNameNew = ''; $scope.seriesSequenceNew = ''; },function onError(data,status,headers,config){ }); //カーソルを戻す }; ------------------------------------------------------------- function getSeries(){ $http({ method: 'POST', url: '/ajax/getSeries', params:{} }).then(function onSuccess(data,status,headers,config){ $scope.serieses = data.data; },function onError(data,status,headers,config){ $scope.serieses = []; }); }
あなたの回答
tips
プレビュー